Field Validation on Lost Focus through Java Scrpit

How we can validate filed on lost focus on the field in any doctype. Please direct towards the solution!

If I’m not mistaken, using frappe.ui.form.on with the field name as trigger will run when the field lost focus.

Thanks for responding, I can get msg on save of doctype by the following scrip, Need pointing how to amend it to trigger on the lost focus of field instead of form save.

frappe.ui.form.on("Knee Assessment", "validate", function(frm) {
        if (frm.doc.knee_left_joint_space_measurement_by_verniar_calipers < 5) {
            frappe.msgprint (__("You can not select less than 5"));
            frappe.validated = false;
        }
                   
    });

Hi @CA_B.C_Chechani, instead of “validate” use field name
ex:
frappe.ui.form.on(“Knee Assessment”, {
field_name: function(frm) {
if(frm.doc.knee_left_joint_space_measurement_by_verniar_calipers < 5)
{
frappe.msgprint (__(“You can not select less than 5”));
}
}
});

Thanks for response , It could work with below, please suggest any improvement

  frappe.ui.form.on("Knee Assessment", "extension_left", function(frm){
        if (frm.doc.extension_left < 5) {
            frappe.msgprint(__("You can not select less than 5"));
            frappe.validated = false;
        }
        
         if (frm.doc.extension_left > 20) {
            frappe.msgprint(__("You can not select more than 20"));
            frappe.validated = false;
        }
    });

As @Nivedha mentioned, this is a trigger. If using a field’s name, the script runs when there is change of value in the field. There is a documentation for this (Form Scripts)

And for your last post, if it works what improvement do you need more? Is there any error, etc?

ADD:
And for ui dialog here are the docs:
js: Dialog API
py: Dialog API

1 Like