I have a Child Doc Type in which I have two fields. One for Selecting the doc type and another field for selecting the field in that doctype.
I used some script to do that
frappe.ui.form.on("Some Parent", {
refresh: function (frm) {
// Attach the change event to the child table.
frm.fields_dict["child_table_name"].grid.wrapper.on(
"change",
'input[data-fieldname="field_doc_type"]',
function () {
update_template_field_option_names(frm);
},
);
},
// Trigger when the form is loaded or the child table is refreshed
onload_post_render: function (frm) {
frm.fields_dict["text_template_fields"].grid.wrapper.on(
"change",
'input[data-fieldname="field_doc_type"]',
function () {
update_template_field_option_names(frm);
},
);
},
});
function update_template_field_option_names(frm) {
frm.doc.text_template_fields.forEach((row, index) => {
let field_doc_type = row.field_doc_type;
if (field_doc_type) {
frappe.model.with_doctype(field_doc_type, () => {
let fields = frappe.get_meta(field_doc_type).fields;
// Filter only input fields.
let input_fieldtypes = [
"Data",
"Select",
"Date",
"Datetime",
"Time",
"Currency",
"Int",
"Float",
"Check",
"Text",
"Small Text",
"Long Text",
"Link",
"Dynamic Link",
"Password",
"Read Only",
"Attach",
"Attach Image",
];
// Use fieldname as value.
let options = fields
.filter((field) => input_fieldtypes.includes(field.fieldtype))
.map((field) => field.fieldname);
console.log(options);
console.log(frm.doc.name);
// Update field options for the child table.
frm.fields_dict["text_template_fields"].grid.update_docfield_property(
"field_name",
"options",
[""].concat(options),
);
// Refresh the specific field in the child table.
frm.fields_dict["text_template_fields"].grid.refresh();
});
}
});
}
I’m adding the options through the script dynamically, and receiving this error when I save the document
Row #1: Field Name cannot be “<selected_option>”. It should be one of “Select”
How to add options for a Select field in a child doc dynamically
I just want a table where I can select a doctype and it’s property