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
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
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.
What code did you use ?
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.
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;
};
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
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;
};