Solution : Create Simple Dependent Dropdown list (from child table rows)

Use Case : Creating dependent dropdown list for : Cars Makes and Cars models within that specific make: I will define my data structure as follows:

  1. Vehicle Make DocType:
  • Fields:
    • make (Data: Text, mandatory)
    • models (Table type field, linked to child DocType “Vehicle Model”)
  1. Vehicle Model DocType: (Child DocType)
  • Fields:
    • model (Data: Text, mandatory)
  1. Vehicle Type DocType: this is the main doctype where I will connect the makes and models to:
  • Fields:
    • make (Link: Vehicle Make)
    • model (Link: Vehicle Model)
  1. Create client-side script:
    on “Vehicle Type DocType” and create this script:
frappe.ui.form.on('Vehicle Type', {
    make: function(frm) {
        frm.set_value('model', ''); // Clear the model field when make changes
        frm.set_query('model', function() {
            return {
                filters: 
                  {
                    'parent': frm.doc.make // Filter models based on the selected make
                }
            };
        });
    }
});

Hope it could help someone new to frappe like me, as i spent a lot of time searching for it. :sweat_smile:

5 Likes