I am trying to implement validation for webform and I have the below code.
frappe.web_form.after_load=()=>{
//Phone number
frappe.web_form.on('phone_number',(field,value)=>{
if(!(CheckSpecialchar(value)==false && CheckAlphabets(value)==false && value.length==10)){
frappe.throw(__('Invalid mobile number'))
}
});
The issue with above method is it will not wait for user to complete the input rather it will start throwing the error on each second idle. is there any way to implement validation which will wait until user finishes his input then validate the field and display the error if any
In you client scrip on your From your form you can get the value from the field you want to validate.
This is executed once you hit save
If you return true on the validation the entry is saved, else it will show the error on a msgprint.
you can add as many messages to msgprint as you want all they will show up on the message
frappe.web_form.validate = () => {
value = frappe.web_form.get_value("product_sku");
frappe.web_form.set_value("product_barcode",value);
if (value.startsWith("SKU"))
return true;
else
frappe.msgprint("Please make sure that your SKU starts with SKU");
return false;
};
you can add as many frappe.msprint as you want they will all show at the same time
frappe.msgprint(“Message1”);
frappe.msgprint(“Message2”);
frappe.msgprint(“etc”);