lleleu
September 16, 2015, 7:58am
#1
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!
lleleu
September 16, 2015, 8:00am
#2
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);
}
}
rmehta
September 17, 2015, 6:53am
#3
I can’t replicate this on my system. What version are you using? Also do you have some other errors?
lleleu
September 18, 2015, 4:33am
#4
Hi rmehta, first thanks for all your answers
I’m on version 5
I have no other errors with the framework.
rmehta
September 18, 2015, 7:07am
#5
I was able to get this working. So am not sure why it fails for you. Can you update to the latest and check?
lleleu
September 18, 2015, 8:57am
#6
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)