Hi,
If I have a child table with multiple fields that I would like to trigger on, how can I achieve this?
For e.g., in the function below, I can currently trigger area calculation when the width is changed. But I would like to recalculate area when the length is changed as well.
Thanks
frappe.ui.form.on("Building Dimensions", "width", function(frm, cdt, cdn) {
var total_area = 0.0;
var dimensions = frm.doc.dimensions;
for(var i in dimensions) {
dimensions[i].area = dimensions[i].length * dimensions[i].width
total_area += dimensions[i].area
}
frm.set_value("total_area",total_area)
frm.set_value("total_area_sqft", total_area*10.76391)
});
you can try refresh
frappe.ui.form.on("Building Dimensions", "refresh", function(frm, cdt, cdn) {
//script
}
or make common function and call it on each field trigger.
frappe.ui.form.on("Building Dimensions", "length", function(frm, cdt, cdn) {
common_function()
}
same for all fields
frappe.ui.form.on("Building Dimensions", "width", function(frm, cdt, cdn) {
common_function()
}
2 Likes
Thanks for the reply @Sangram
refresh
doesn’t work (maybe since it’s a child table?)
Will use option two for now.
Thanks
Hi @ishanloya! How about refreshing the child table:
cur_frm.refresh_field("items")
@creamdory, thanks for your reply but I’m not sure how to go about doing that.
For now, I’ve followed @Sangram’s advice and changed my code to:
function area_calc(frm, cdt, cdn) {
var total_area = 0.0;
var dimensions = frm.doc.dimensions;
for(var i in dimensions) {
dimensions[i].area = dimensions[i].length * dimensions[i].width
total_area += dimensions[i].area
}
frm.set_value("total_area",total_area)
frm.set_value("total_area_sqft", total_area*10.76391)
}
frappe.ui.form.on("Building Dimensions", "length", area_calc)
frappe.ui.form.on("Building Dimensions", "width", area_calc)
2 Likes
Hi @ishanloya! It works like a refresh but on the child level. The “items” is the child doctype name. 