Shaun Summers
Posts: 0
Joined: Thu Jul 25, 2013 3:49 pm

Stop other events if validation fails

Hi,

I've created a javascript event to check whether fields are completed. The event executes when the submit form button is clicked. The script (see below) works find and a message is displayed. The issue is that once I acknowledge the error the remaining event (navigate to page) is executed anyway.

How do I stop other events being run when an issue is detected in the form?

codeif ($.trim(Appery("enter_name").val()) != "") {
} else {
alert("Please enter your name");
}
/code

Regards, Shaun

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Stop other events if validation fails

Hello!

Could you check are there any errors in console?

Shaun Summers
Posts: 0
Joined: Thu Jul 25, 2013 3:49 pm

Stop other events if validation fails

When I use the console javascript in Chrome I get no errors displayed.

Regards, Shaun

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Stop other events if validation fails

Hi Shaun.

Please follow these steps:

1 Delete all other click event handlers on this button.

2 Use following code to for your "click" event handler:

pre
code

if ($.trim(Appery("enter_name").val()) != "") {
//Do if validation in passed.

Code: Select all

 //This code navigate user to "Screen2" page. You should change it with your needs. 
 Apperyio.navigateTo("Screen2") 

} else {
//Do if validation is not passed.
alert("Please enter your name");
}

/code
/pre

So reaction on this button would be defined only from this code.

Regards.

Shaun Summers
Posts: 0
Joined: Thu Jul 25, 2013 3:49 pm

Stop other events if validation fails

Hello,

This worked fine in the situation where I need to just navigate to another page.

In another example I now need to validate the form, invoke a service and navigate to another page.

I assume I would take the same approach on deleted the click event handler for the service and including it in the javascript. My question is what is the syntax for the name of the service? My service is called "MySizeIn_Sizes_Create_Service"

code
if ($.trim(Appery("enter_name").val()) != "") {

Code: Select all

 Apperyio.navigateTo("Screen2"); ????service name????.execute({}); 

}
else {
alert("Please enter your name");
}
/code

Shaun Summers
Posts: 0
Joined: Thu Jul 25, 2013 3:49 pm

Stop other events if validation fails

I worked it out. I needed to include the name that I had given to my services in the data tab.

code
if ($.trim(Appery("enter_name").val()) != "")
{
if ($.trim(Appery("enter_fav_brand").val()) != "")

{Apperyio.navigateTo("MySizeIn"); Create_brand.execute({}); Create_person.execute({});}

else {alert("Please enter your preferred brand");}
}else {alert("Please enter your name");}
/code

Return to “Issues”