Dan6766536
Posts: 0
Joined: Thu Mar 27, 2014 6:21 pm

Mandatory Fields

Hi. I've used appery.io to build a simple app to collect information from my customers. I want to make it mandatory for all the app input fields to be populated before a customer can submit data. How do I acheive that? Dan

Nikita
Posts: 0
Joined: Fri Feb 28, 2014 4:02 pm

Mandatory Fields

Hello,

You should add a handler to the "submit" button, that will verify all the required fields and prevent its sending, if the data isn't entered.

Janise Dismuke
Posts: 0
Joined: Mon Apr 14, 2014 8:24 pm

Mandatory Fields

What code did you use ?

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

Mandatory Fields

Hi Janise.

It's up to you what code to use.

But you can use following one(add this to the submit button click):

'''

//name_field - is a name of the input component that's need to be validated on empty value.
var name = Appery("name_field").val();

//Validation condition
if(name == ""){
alert("Please fill the name field");

Code: Select all

 //Get out here if validation not passed 
 return; 

};

//Run update/create service if validation is passed.
serviceName.execute({});

'''

Regards.

Dan Hoeck
Posts: 0
Joined: Sat May 17, 2014 3:55 am

Mandatory Fields

This is very helpful! The one thing I could use, to add to this, is how do you add validation of a radio button?

I am using the following script which is not working:

var radioButton = Appery("mobileradiobutton_1").checked;

if(radioButton == "false"){
alert("Please select an option from the list");

return;
};

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Mandatory Fields

Hello Dan,

Let's try using this code:

codevar radioButton =$('input[name=mobileradiogroup_5]:checked').val();

if(radioButton){
alert("Please select an option from the list");

return;
}; /code
where "mobileradiogroup_5" is the name of your radiogroup component

Dan Hoeck
Posts: 0
Joined: Sat May 17, 2014 3:55 am

Mandatory Fields

Thank you, this worked! I just had to add in -- if(radioButton == null)
otherwise the following code worked great:

var radioButton =$('input[name=mobileradiogroup_5]:checked').val();

if(radioButton -- null){
alert("Please select an option from the list");

return;
};

Return to “Issues”