How I Make Field In table ( Is Mandatory Field ) Depends On field == (Accessories)

I am assuming both item_category and employee fields are in item table.

You can change df property to make it mandatory but not differently for each row as system will change df property of field in grid not grid-row (check below):

frappe.ui.form.on('Material Request Item', {
	category_item: function(frm, cdt, cdn) {
		const row = locals[cdt][cdn];
		var current_row = frm.fields_dict["items"].grid.grid_rows_by_docname[row.name];
		current_row.toggle_reqd("employee", (row.category_item === "Accessories"));
	},

});

However, you can use validate to check value of item field based on required condition as mentioned below:

cur_frm.cscript.validate = function(doc, cdt, cdn) {
	if(doc.with_items){
		$.each(doc["items"] || [], function(i, item) {
			if (item.category_item === "Accessories" && !item.employee){
				frappe.msgprint(__("Row#{0} Please enter employee.", [item.idx]));
				frappe.validated = false;
			}
		});
	}

}
1 Like