Select Type: how to make it default selected

frappe.ui.form.on("Lead", "state", function(frm) {
  if(frm.doc.state == "Karnataka")
  {
    set_field_options("city", ["Bangalore","Mysore"])
  }
  else if(frm.doc.state == "Maharashtra")
  {
    set_field_options("city", ["Mumbai","Pune"])
  }
  else if(frm.doc.state == "")
  {
    set_field_options("city", ["","Bangalore","Mysore","Mumbai","Pune"])
  }
  });

Anyway we can make option selected ,

example if(frm.doc.state == "") I want “Pune” to be selected by default.

Hi @treeem,

Please try it.

frappe.ui.form.on("Lead", "state", function(frm) {
  if(frm.doc.state == "Karnataka") {
    set_field_options("city", ["Bangalore","Mysore"]);
  }
  else if(frm.doc.state == "Maharashtra") {
    set_field_options("city", ["Mumbai","Pune"]);
  }
  else if(frm.doc.state == "") {
    set_field_options("city", ["","Bangalore","Mysore","Mumbai","Pune"]);
    cur_frm.set_value("city", "Pune"); // Set "Pune" as the default selected option
  }
});

Then reload and check it.

Thank You!

1 Like