MANDATORY FIELD- Material Request Doctype

Hello,

Question,

Is it possible to set a mandatory field that only depend to other field?

example below


** this is material request doctype

Project field will only display and is mandatory when the drop down or purpose of the material request iis “Material Issue”

but when the Purpose is to Purchase the project is not mandatory and hidden.

Thank you

if(frm.doc.material_request_type=="Material Issue") {
	frm.set_df_property("project", "reqd", 1);
}

You can add this in the js file of the DocType to toggle a field as mandatory upon some condition.

1 Like

Hello,

I paste this code under project in Material Request but it is not working :frowning:

Try using it from onload or setup function. Project function will only be triggered after you enter something in its field.

Hello,

sorry sir but we don’t get it. i tried entering items but it still doesn’t display.

thank you

Hi @ossphinc

Got to “Setup > Custom Script > New”, enter “Material Request” as “DocType” and enter the following script into “Script”:

frappe.ui.form.on("Material Request", {
  refresh: function(frm) {
    if(frm.doc.material_request_type=="Material Issue") {
		frm.set_df_property("project", "reqd", 1);
	}
  }
});

Save - Now it should work properly :slight_smile:

Cheers!

5 Likes