Filter for select field type

Hello;

How I can restrict the options of the Select field based on another field?
For example: in the below image, order field is select type and I need to restrict the Buy and Compensate options to appear if the Status is Available and the option Not Allowed if the status is Taken. How?

Regards
Bilal

Write a custom script for on change status event

Try this script in your Parent Doctype,

frappe.ui.form.on("Child Table Name", {
	status: function(frm,cdt, cdn){
		restrict_order(frm, cdt, cdn);
	}
});
var restrict_order = function(frm, cdt, cdn) {
    var child = locals[cdt][cdn];

    if (child.status == "Available")
    {
        frappe.model.set_df_property("order", "options", ["Buy", "Compensate"]);
    }
    else if (child.status == "Taken") {
        frappe.model.set_df_property("order", "options", ["Not Allowed"]);
    }
}
2 Likes