feat: make option sorting configurable
This commit is contained in:
parent
0cfcfe4c51
commit
49ccc0ab6e
5 changed files with 38 additions and 10 deletions
|
|
@ -21,6 +21,7 @@
|
|||
"search_index",
|
||||
"column_break_18",
|
||||
"options",
|
||||
"sort_options",
|
||||
"show_dashboard",
|
||||
"defaults_section",
|
||||
"default",
|
||||
|
|
@ -550,13 +551,20 @@
|
|||
"fieldtype": "Data",
|
||||
"label": "Documentation URL",
|
||||
"options": "URL"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"depends_on": "eval: doc.fieldtype === 'Select'",
|
||||
"fieldname": "sort_options",
|
||||
"fieldtype": "Check",
|
||||
"label": "Sort Options"
|
||||
}
|
||||
],
|
||||
"idx": 1,
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-02-20 12:07:29.552523",
|
||||
"modified": "2023-06-08 18:31:50.153235",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Core",
|
||||
"name": "DocField",
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
"hide_seconds",
|
||||
"hide_days",
|
||||
"options",
|
||||
"sort_options",
|
||||
"fetch_from",
|
||||
"fetch_if_empty",
|
||||
"options_help",
|
||||
|
|
@ -435,13 +436,20 @@
|
|||
"fieldtype": "Check",
|
||||
"label": "Is System Generated",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"depends_on": "eval: doc.fieldtype === 'Select'",
|
||||
"fieldname": "sort_options",
|
||||
"fieldtype": "Check",
|
||||
"label": "Sort Options"
|
||||
}
|
||||
],
|
||||
"icon": "fa fa-glass",
|
||||
"idx": 1,
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2022-06-13 06:39:03.319667",
|
||||
"modified": "2023-06-08 18:33:28.863144",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Custom",
|
||||
"name": "Custom Field",
|
||||
|
|
|
|||
|
|
@ -665,6 +665,7 @@ docfield_properties = {
|
|||
"label": "Data",
|
||||
"fieldtype": "Select",
|
||||
"options": "Text",
|
||||
"sort_options": "Check",
|
||||
"fetch_from": "Small Text",
|
||||
"fetch_if_empty": "Check",
|
||||
"show_dashboard": "Check",
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
"precision",
|
||||
"length",
|
||||
"options",
|
||||
"sort_options",
|
||||
"fetch_from",
|
||||
"fetch_if_empty",
|
||||
"show_dashboard",
|
||||
|
|
@ -462,13 +463,20 @@
|
|||
"fieldname": "ignore_xss_filter",
|
||||
"fieldtype": "Check",
|
||||
"label": "Ignore XSS Filter"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"depends_on": "eval: doc.fieldtype === 'Select'",
|
||||
"fieldname": "sort_options",
|
||||
"fieldtype": "Check",
|
||||
"label": "Sort Options"
|
||||
}
|
||||
],
|
||||
"idx": 1,
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-02-20 12:07:40.242470",
|
||||
"modified": "2023-06-08 18:36:22.833032",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Custom",
|
||||
"name": "Customize Form Field",
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ frappe.ui.form.ControlSelect = class ControlSelect extends frappe.ui.form.Contro
|
|||
if (this.$input) {
|
||||
var selected = this.$input.find(":selected").val();
|
||||
this.$input.empty();
|
||||
frappe.ui.form.add_options(this.$input, options || []);
|
||||
frappe.ui.form.add_options(this.$input, options || [], this.df.sort_options);
|
||||
|
||||
if (value === undefined && selected) {
|
||||
this.$input.val(selected);
|
||||
|
|
@ -102,15 +102,18 @@ frappe.ui.form.ControlSelect = class ControlSelect extends frappe.ui.form.Contro
|
|||
}
|
||||
};
|
||||
|
||||
frappe.ui.form.add_options = function (input, options_list) {
|
||||
frappe.ui.form.add_options = function (input, options_list, sort) {
|
||||
let $select = $(input);
|
||||
if (!Array.isArray(options_list)) {
|
||||
return $select;
|
||||
}
|
||||
|
||||
options_list
|
||||
.map((raw_option) => parse_option(raw_option))
|
||||
.sort((a, b) => a.label.localeCompare(b.label))
|
||||
let options = options_list.map((raw_option) => parse_option(raw_option));
|
||||
if (sort) {
|
||||
options = options.sort((a, b) => a.label.localeCompare(b.label));
|
||||
}
|
||||
|
||||
options
|
||||
.map((option) =>
|
||||
$("<option>")
|
||||
.html(cstr(option.label))
|
||||
|
|
@ -128,8 +131,8 @@ frappe.ui.form.add_options = function (input, options_list) {
|
|||
|
||||
// add <option> list to <select>
|
||||
(function ($) {
|
||||
$.fn.add_options = function (options_list) {
|
||||
return frappe.ui.form.add_options(this.get(0), options_list);
|
||||
$.fn.add_options = function (options_list, sort) {
|
||||
return frappe.ui.form.add_options(this.get(0), options_list, sort);
|
||||
};
|
||||
$.fn.set_working = function () {
|
||||
this.prop("disabled", true);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue