From 421ed06a48fcee2a8cc657b97697d3b958522bf4 Mon Sep 17 00:00:00 2001 From: Basawaraj Savalagi Date: Sat, 1 Dec 2018 10:52:25 +0530 Subject: [PATCH] Added custom script example to limit options in select field dynamically --- .../dynamically-show-options-in-dropdown.md | 16 ++++++++++++++++ .../custom-script-examples/index.txt | 1 + 2 files changed, 17 insertions(+) create mode 100644 foundation/www/docs/user/manual/en/customize-erpnext/custom-scripts/custom-script-examples/dynamically-show-options-in-dropdown.md diff --git a/foundation/www/docs/user/manual/en/customize-erpnext/custom-scripts/custom-script-examples/dynamically-show-options-in-dropdown.md b/foundation/www/docs/user/manual/en/customize-erpnext/custom-scripts/custom-script-examples/dynamically-show-options-in-dropdown.md new file mode 100644 index 00000000..e14377e5 --- /dev/null +++ b/foundation/www/docs/user/manual/en/customize-erpnext/custom-scripts/custom-script-examples/dynamically-show-options-in-dropdown.md @@ -0,0 +1,16 @@ +# Dynamically Update Options in Select Field + +Lets say you have a field named state and another field named city. And you would like to limit options in city based on the values chosen in state field, you can write custom script as shown below. + + frappe.ui.form.on("DocType Name Here", "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"]) + } + }); + + {next} diff --git a/foundation/www/docs/user/manual/en/customize-erpnext/custom-scripts/custom-script-examples/index.txt b/foundation/www/docs/user/manual/en/customize-erpnext/custom-scripts/custom-script-examples/index.txt index 2b497555..06e02297 100755 --- a/foundation/www/docs/user/manual/en/customize-erpnext/custom-scripts/custom-script-examples/index.txt +++ b/foundation/www/docs/user/manual/en/customize-erpnext/custom-scripts/custom-script-examples/index.txt @@ -8,3 +8,4 @@ restrict-user-based-on-child-record sales-invoice-id-based-on-sales-order-id update-date-field-based-on-value-in-other-date-field custom-button +dynamically-show-options-in-dropdown