Hello,
Is it possible to update a child table field label after the form has rendered?
I have a child table (Detail) that has week day fields (ex: monday, tuesday…).
I want to choose a date (week) in the parent record and for each day of the week, in the child table form, update the label to display the week day, month and day. (ex: Mon (May 15), Tuesday (May 16)).
I am able to update the field labels on the list and on the form using the onload event.
onload(frm) {
if (frm.is_new()) {
frm.trigger('week');
} else {
frm.set_df_property('week', 'label', `Week ${moment(frm.doc.week).week()}`);
update_week_day_labels(frm)
}
},
week(frm) {
const startOfWeek = moment(frm.doc.week).startOf("week").format()
frm.set_value("week", startOfWeek);
frm.set_df_property('week', 'label', `Week ${moment(frm.doc.week).week()}`);
update_week_day_labels(frm)
frm.refresh()
},
Bellow is the helper function that updates the labels
const update_week_day_labels = function (frm) {
const fieldNames = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]
const startOfWeek = moment(frm.doc.week).startOf("week").format()
const fieldsMap = frappe.meta.docfield_map['Detail']
fieldNames.forEach((fieldName, index) => {
const date = moment(startOfWeek).add(index, 'days')
// Format: WeekDay (Month Day)
const label = `${date.format("ddd")} (${date.format("MMM D")})`
// Updates field labels in form
let field = frappe.meta.get_docfield("Detail", fieldName, frm.doc.name)
field.label = label
// Updates field labels in the grid
fieldsMap[fieldName].label = label
})
}
This works well when the form loads for the first time.
The problem is that when I change the week field value, I want to update the labels again. With this code the labels in the grid are updated, but the labels inside the child record form are not.
If we log the values in the code they are updated but it seems like the form does not rerender when we edit a record. Is it possible to trigger a rerender or am I missing something?
Thanks, João