Hey guys. Yesterday I was creating my custom doctype and custom field.
And I put some custom script on my custom field.
My custom field that can make calculation and show the result.
After that I put “read-only” custom script.
The result is I need to click on save twice then the the status change to “save”
My question is, how to automate the calculation without clicking on save button and how to make the record save only for one “click” (save button)?
frappe.ui.form.on("Employee Receipt", {
refresh: function(frm) {
// use the __islocal value of doc, to check if the doc is saved or not
frm.set_value("balance_need_to_pay", (frm.doc.total_need_to_pay - frm.doc.payment));
frm.set_df_property("balance_need_to_pay", "read_only", frm.doc.__islocal ? 0 : 1);
}
});
frappe.ui.form.on("Employee Receipt", {
refresh: function(frm) {
// use the __islocal value of doc, to check if the doc is saved or not
frm.set_value("balance_need_to_pay", (frm.doc.total_need_to_pay - frm.doc.payment));
frm.set_df_property("balance_need_to_pay", "read_only", frm.doc.__islocal ? 1 : 1);
frm.refresh_field('balance_need_to_pay');
}
});
Its okay guys.
I already fixed it.
I just add new trigger “validate” to validate the calculation.
Here is my code:
// make calculation on fields
frappe.ui.form.on("Employee Receipt", {
validate: function(frm) {
frm.set_value("balance_need_to_pay", (frm.doc.total_need_to_pay - frm.doc.payment));
frm.refresh_field('balance_need_to_pay');
}
});
// make a field read-only after saving
frappe.ui.form.on("Employee Receipt", {
refresh: function(frm) {
// use the __islocal value of doc, to check if the doc is saved or not
frm.set_df_property("balance_need_to_pay", "read_only", frm.doc.__islocal ? 0 : 1);
}
});