When submitting a form, I tried to submit the form by using the id and call submit on it by JQuery, but offcourse, the first script gets me in an infinite loop.
After using plupload, I noticed that they use another way to submit the form, which doesn't cause an infinite loop.
I tried to find information about this, but I cannot seem to get specific information about this?
$('#test').submit(function(e) {
alert("here");
$('#test').submit();
return false;
});
$('form').submit(function(e) {
alert("here");
$('form')[0].submit();
return false;
});
Begin edit
In first case you are triggering the jQuery submit event on your jQuery object (see http://api.jquery.com/submit/)
In second case, you are calling the javascript submit method on a javascript object. It does not trigger the submit event.
It is not the same 'submit' in both case.
In your second case, if you replace :
$('form')[0].submit();
with
$($('form')[0]).submit();
you will also end up with an infinite loop.
End edit
in fact, with plupload, the point is waiting for the time when you will be able to successfully submit the form. The main feature is subscribing to StateChanged event.
It works this way :
1- first check if the queue is empty. If so, validate form submission(return true)
2- if the queue is not empty
a- startuploading remaining files
b- subscribe to future 'StateChanged' events where it will check the queue. If it is empty at that time, goto step 1 that will pass successfully (because the queue will be empty at that time)
c - cancel form submission (the queue is not currently empty)
Some code with comments :
// Client side form validation
$('form').submit(function(e) {
var myForm = e.currentTarget;
var uploader = $(item).pluploadQueue();
// if files in queue upload them first. Cancel current form submission.
// Subscribe to 'StateChanged' to check if the queue is empty and try
// a new submission, each time a file is finished uploading
if (uploader.files.length > 0) {
// When all files are uploaded submit form
uploader.bind('StateChanged', function() {
if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
myForm.submit(); //
}
});
// start uploading remaining files.
// End of each upload will trigger the 'StateChanged'
uploader.start();
// there are files in queue. (the reason we are running current block)
// Cancel current form submission
return false;
}
return true; // the queue is empty, validate current form submission
});
Hope this will help
Related
My 'create new User' app can only create one new user. If I want to create an additional user I have to restart the app. What I want to do is, create some button which does this task without restarting the app.
To be more specific, after the initial call of the app I create a new user (include save). The user is stored in the back-end and still visible on the front-end (so I can further edit the user). In case I want to create an additional user, I want to push some button and the view will be restarted/reloaded (and also the Model). Eventually I want the inital state of my app. Then I want to be able to create the next new user (include save) and maybe another one.
What I already tried:
'CrossApplicationNavigation' to my 'create new user' app without any
parameters. It works only the first time, because when I push the
button the second time nothing happens. The URL stays the same (no parameters are changing).
Deleting data of the Model and subsequently calling the oninit()
function. But I get problem with refilling the model.
Is there some function or something else I can try?
As descripted in comment (component.js):
init: function () {
//set model
this.setModel(models.createTableModel(this), "table");
if (this.getComponentData().startupParameters.ID) {
var sID = this.getComponentData().startupParameters.ID[0];
if (sID !== "") {
this.getModel("table").setProperty("/ID", sID);
} else {
this.getModel("table").setProperty("/ID", "");
}
}
}
I think, you're using a local model? Then you'll have to reset your local model. Reset your local model in onInit function and on pressing button "Add new user".
onInit: function(){
this.oLocalModel = this.getModel("myLocalModel");
this._resetModel(this.oLocalModel);
},
_resetModel: function(oModel){
oModel.setData();
},
onPressAddNewUser: function(){
this._resetModel(this.oLocalModel);
}
I have an ion toggle in my application that stores his status in a firebase Database, is there a way to change his status with the data loaded from firebase?
For example, if in the database the status is true, then when I load the view the toggle will be on. I've tried using checked:
<ion-toggle checked="status()" >
where status() returns a boolean.
But due to the async function of firebase, the view loads 1st before the value in status(). Can't find a solution to this problem so far, I'd apreciate any help.
Yes there's a way to do this, but using a function in your attribute is no good. When using a function in the DOM that returns a value you'll make that function executes every time there's a change in the DOM, so since this is a function that fetchs something on Firebase you'll make your user do an request to Firebase every time the DOM is updated.
A good way to do this is storing the Firebase result in a variable. you can do like this when you enter de page:
public myStatus: boolean;
// USING A LIFECYCLE HOOK
ionViewWillLoad(){
firebase.database().ref(`Path/To/Your/Status`).once('value', snapshot => {
this.myStatus = snapshot.val();
});
}
And in your HTML
<ion-toggle [checked]="myStatus">
<!-- You need to bind your checked attribute to myStatus, using checked="{{myStatus}}" also works -->
If you need to always check if your status has changed you can also create and observable on firebase, so if your status change you can change your toggle:
ionViewWillLoad(){
firebase.database().ref(`Path/To/Your/Status`).once('value', snapshot => {
this.myStatus = snapshot.val();
});
firebase.database().ref(`Path/To/Your/Status`).on('child_changed', snapshot => {
this.myStatus = snapshot.val();
});
// YOU'LL NEED BOTH SINCE THE FIRST LOADS THE STATUS FOR THE FIRST TIME AND THE SECCOND CREATES AN OBSERVABLE FOR WHEN THE STATUS CHANGE.
}
Hope this helps.
I am writing a code that aims to inform me via e-mail if a value on a website changes. In order to do so, I use 4 functions:
function one executes functions 2-4
function 2 is a scraper
function 3 writes the data in a new line in a spreadsheet
function 4 compares the newly written line and sends out an e-mail if the new line is different from the one before.
Function one is triggered automatically every 5 minutes. The spreadsheet shows that the trigger works fine for function two and three (scrape and save the data to the spreadsheet), every five minutes the spreadsheet is being updated. I do not, however, get an e-mail when something changes.
When I execute function one manually, it works, including e-mails being send out if the data changed. I tried to add an additional trigger to just execute the function that compares the data and sends an e-mail. That, however, also did not lead to e-mails being sent to me.
If it matters: The data change about once an hour. I however, want to get informed asap, hence the frequent checks
Do you have any idea, why the trigger for sending out the e-mails does not work and do you have any solution for me?
Thanks in advance!
function scrape_save_send(){
getData();
saveData();
SendEmail();
}
function getData() { // works just fine, code cut to make it not too long
[...]
}
function saveData() { // works fine both automatically and manually
var sheet = SpreadsheetApp.getActiveSheet();
sheet.appendRow([new Date(), getData()]);
var lrow = sheet.getLastRow();
sheet.getRange(lrow,3).setFormula('=SPLIT(B'+lrow+'; "abcdefghijklmnopqrstuvwxyz=<>- /")') // workaround to extract a number from the scraped content
}
function SendEmail() { // works just fine if executed manually
Utilities.sleep(2000) // delays the check
var sheet = SpreadsheetApp.getActiveSheet();
var lastRow = sheet.getLastRow();
var ui = SpreadsheetApp.getUi();
if (sheet.getRange(sheet.getLastRow()-1,2).getValue() === sheet.getRange(sheet.getLastRow(),2).getValue()) {
Logger.log('equal');
} else {
var invest = sheet.getRange(sheet.getLastRow(),8).getValue();
MailApp.sendEmail("ab#gmail.com", invest + "blablabla", "blablabla");
// Logger.log('not equal');
}
}
Try changing MailApp to GmailApp in the last line of SendEmail() function.
I found the solution: the getUi()-function apparently caused the problem. Some research showed me that the getUi()-function only works when the according sheet is opened.
Since I don't need the function (it was left over from an old function) I deleted it, the script now works automatically. Thanks!
I have a protractor test that navigates to another url, which cannot be found/resolved in my test environment, so I check if the title is not the previous title.
The test is as follows:
it('should navigate to another site in case of click on cancel link', function () {
page.navigate();
page.submit();
protractor.getInstance().ignoreSynchronization = true;
browser.wait(function(){
return element(by.id('submit')).isPresent();
});
page.closePage();
// the title of a 404, dns issue etc is at least different from the previous site:
expect(browser.getTitle()).not.toEqual('MyDummyTitle')
protractor.getInstance().ignoreSynchronization = false;
});
This works in most browsers, but in Internet Explorer I find that it often is not ready navigating to the non-existing page when the expect is fired.
Can I somehow wait for the 'submit' element to be gone, similar to what I do before firing the closePage?
What I do in this cases is an active wait of an element to disappear:
Using a custom waitAbsent() helper function that actively waits for an element to disappear either by becoming invisible or by not being present.
That helper waits up to specTimeoutMs ignoring useless webdriver errors like StaleElementError.
Usage: add require('./waitAbsent.js'); in your onPrepare block or file.
Example to wait for #submit to be gone:
expect(element(by.id('submit')).waitAbsent()).toBeTruthy();
I am wanting to know a button is rendered on main window UI or not. This button rendering is depending on server response result (written in Objective C). If server response comes perfectly it becomes render perfectly (VISIBLE) otherwise it is not present there (INVISIBLE). And whenever it becomes visible I always tap on it for further next process.
I wrote code
UIATarget.localTarget().pushTimeout(200);
//My code
UIATarget.localTarget().popTimeout();
By the above code I have to wait till 200 sec but my concern is I want to wait but whenever object is on screen I don't want keep me busy in WAITING MODE.
How will I write code in automation?
Thanks
Ok, this might give you idea how to follow-up:
For your view implement an accessibilityValue method which returns a JSON formatted value:
- (NSString *)accessibilityValue
{
return [NSString stringWithFormat:
#"{'MyButtonisVisible':%#}",
self.MyButton.isHidden ? #"false" : #"true"];
}
Then somehow you can access it from your test javascript:
var thisproperty = eval("(" + element.value() + ")");
if (thisproperty.MyButtonisVisible) {
UIATarget.localTarget().tap({"x":100, "y":100});
}
Hope that helps.
If you make the name different when you enable the button you can do this:
var awesomeButton = target.frontMostApp().mainWindow().buttons()[0];
UIATarget.localTarget().pushTimeout(200);
awesomeButton.withName("My Awesome Button");
if (awesomeButton.isVisible()) {
UIALogger.logError("Error no awesome button!");
}
UIATarget.localTarget().popTimeout();
withName will repeatedly test the name and control will return to your script once the name matches or when the time out is reached.
Per Apple's Doc
withName:
Tests if the name attribute of the element has the given string value. If the match fails, the test is retried until the current timeout expires.
Timeout Periods:
If the action completes during the timeout period, that line of code returns, and your script can proceed. If the action doesn’t complete during the timeout period, an exception is thrown.
https://developer.apple.com/library/etc/redirect/xcode/ios/e808aa/documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/UsingtheAutomationInstrument/UsingtheAutomationInstrument.html#//apple_ref/doc/uid/TP40004652-CH20