frappe.web_form.validate = async () => {
try{
let data = frappe.web_form.get_values();
console.log('data', data);
// console.log('data.dependent_name.length',data.dependent_name.length)
if(Object.keys(data).length == 0){
alert('Please Enter All The Fields');
}
if(data.dependent_name === "" || !data.hasOwnProperty('dependent_name') || data.dependent_name.length == 0){
alert('Please Enter Name');
return ;
}
if(data.dependent_mail === "" || !data.hasOwnProperty('dependent_mail') || data.dependent_mail.length == 0){
alert('Please Enter Mail');
}
if(data.dependent_phone === "" || !data.hasOwnProperty('dependent_phone') || data.dependent_phone.length == 0){
alert('Please Enter Phone Number');
}
above is the code which takes values from the form and if any field is empty then the form should not be saved after displaying the alert message so how can i do it
thanks @bahaou for the solution I made the fields mandatory, but for below form details, the form is getting saved even though mail entered is not valid
so i need to validate the email and phone number upon submission and save the form only when email and phone number is valid returns True
so how can i do it using client side script
To validate email simply write Email in the option section for the field.
And the Phone field does provide some validation. Eg. if user enter less than 10 digit for number then it prompts
Phone Number +91-7676657 set in field phone is not valid.
hey @bahaou,
even after adding return false; web form is still getting submitted
here is the code
let email_validation = validateEmail(data.dependent_mail)
if(!email_validation){
alert('Please Enter Valid Email');
return false;
}
if email is not valid then the if condition is executing successfully and the line “return false;” is executing but I want the web form not to be submitted and should show a alert message
how can i do it?