Js function call on Form

Hi Everyone!!

I want to call a function when the form is dirty i.e., when frm.is_dirty() is true.

How can i achieve this??

Any suggestions?

Hy @Kiranmai_M,

I don’t know if this exists. When the form is dirty, it stills dirty as long as we are not saving, so you want to call the function an infinity calls ?

Maybe something like this helps you ?

frappe.ui.form.on('YourDoctype', {
    validate: function(frm) {
        if (frm.is_dirty()) {
            my_custom_function(frm);
        }
    },

    // Optionally, track specific field changes
    some_fieldname: function(frm) {
        if (frm.is_dirty()) {
            my_custom_function(frm);
        }
    }
});

function my_custom_function(frm) {
    // Your custom logic here
    console.log("Form is dirty. Running custom function.");
}