Re-enable save button after frappe.throw

Hello everyone,

In the .js file of my action doctype I control that all mandatory fields are filled. If not I throw a msg using frappe.throw. This is working. But after the msg has been displayed the save button is disabled. I can still save with ctrl + s though.

Here is my code:

if (dtd_conditions) {
    validated = false;
    frappe.throw(__("The following fields are compulsory<hr>"
                    + "Number of household visited<br>"
                    + "Number of interested customers<br>"
                    + "Commune<br>"
                    + "Village"));
}

How can I re-enable the save button when the msg is thrown?

Thank you for your help!

I have to specify that this code is in the “cur_frm.cscript.custom_validate = function(doc) {” function:

cur_frm.cscript.custom_validate = function(doc) {
var dtd_conditions = (doc.action_type === "Door to door" &&
                         (!doc.village_dtd || !doc.commune_dtd || !doc.number_hh_dtd || !(doc.number_nic_dtd >= 0)));
if (dtd_conditions) {
    validated = false;
    frappe.throw(__("The following fields are compulsory<hr>"
                    + "Number of household visited<br>"
                    + "Number of interested customers<br>"
                    + "Commune<br>"
                    + "Village"));
} else {
    cur_frm.set_value("workflow_state", "Done");
    var d = get_today();
    cur_frm.set_value("close_date", d);
    window.setTimeout(function(){
            window.history.back();
            return;
    }, 2000);
}

}

I can’t replicate this on my system. What version are you using? Also do you have some other errors?

Hi rmehta, first thanks for all your answers :smile:
I’m on version 5
I have no other errors with the framework.

I was able to get this working. So am not sure why it fails for you. Can you update to the latest and check?

Actually I just have the same problem now with an other doctype (customer doctype of my app).

Here is my code for the validate function in customer.js:

cur_frm.cscript.custom_validate = function(doc) {
if (nok_ent) {
    frappe.throw(__("The following fields are compulsory<hr>"
                    + "Customer gender<br>"
                    + "Customer name<br>"
                    + "Phone one<br>"
                    + "Commune<br>"
                    + "Village"));
} else if (nok_others) {
	frappe.throw(__("The following fields are compulsory<hr>"
                    + "Customer gender<br>"
                    + "Customer name<br>"
                    + "Phone one<br>"
					+ "District<br>"
                    + "Commune<br>"
                    + "Village<br>"
					+ "Sales representative"));
} else if (ok_conditions) {
    doc.interest_date = get_today();
    window.setTimeout(function(){
        window.history.back();
        return;
    }, 2000);
} else {
    window.setTimeout(function(){
        window.history.back();
        return;
    }, 2000);
}

}

Same thing, when a message is thrown, the save button is disabled and I can’t find a way to en-able it again. Is there a way to force the properties of the save btn to enable it?

Facing the Same issue in production environment (version - v8.0.44)