Use Case : Creating dependent dropdown list for : Cars Makes and Cars models within that specific make: I will define my data structure as follows:
- Vehicle Make DocType:
- Fields:
make
(Data: Text, mandatory)models
(Table type field, linked to child DocType “Vehicle Model”)
- Vehicle Model DocType: (Child DocType)
- Fields:
model
(Data: Text, mandatory)
- 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)
- 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.