Hello,
I am trying to make a field read only on the select option as if yes and no. On Yes I want to make all fields read only without saving. How can i do that? Any suggestions?
frappe.ui.form.on("[your doctype]", "[your select field]", function(frm) {
// if field is yes:
$.each(frm.meta.fields, function(index, field)) {
frm.set_df_property(field.fieldname, "read_only", 1);
});
}
Can you suggest an example for the code you’ve mentioned, specifying all the values?
Also, If there are three values in select then what should be done? @snv
Why don’t you try experimenting instead? Because that’s how you learn.
This is basic JS. Add another if
statement. Why would you have three values though?
I have done experimenting. Didn’t got the appropriate result. so thought of asking an example.
frappe.ui.form.on(“Saleable Unit”, “status”, function(frm) {
// if field is yes:
$.each(frm.meta.fields, function(index, status)) {
frm.set_df_property(status.sold, “read_only”, 1);
});
}
The status is having more fields like unsold, sold, hold. That’s the reason I put up that question.
I am a newbie. I googled a solution for this.
Didn’t workout so.
If you can contribute, it would be of great help. @snv
Thanks.
frappe.ui.form.on(“Saleable Unit”, “status”, function(frm) {
if (frm.doc.status === 'Sold') {
$.each(frm.meta.fields, function(index, field)) {
if (field.fieldname != 'status') {
frm.set_df_property(field.fieldname, “read_only”, 1);
}
});
frm.refresh();
}
});
Protip: Go through the tutorials here before continuing.