Merge pull request #26425 from cogk/feat-add-translation-context-to-select-options
This commit is contained in:
commit
f3816fa2ea
1 changed files with 11 additions and 6 deletions
|
|
@ -75,7 +75,12 @@ 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 || [], this.df.sort_options);
|
||||
frappe.ui.form.add_options(
|
||||
this.$input,
|
||||
options || [],
|
||||
this.df.sort_options,
|
||||
this.df.context || this.df.parent || this.doctype
|
||||
);
|
||||
|
||||
if (value === undefined && selected) {
|
||||
this.$input.val(selected);
|
||||
|
|
@ -103,13 +108,13 @@ frappe.ui.form.ControlSelect = class ControlSelect extends frappe.ui.form.Contro
|
|||
}
|
||||
};
|
||||
|
||||
frappe.ui.form.add_options = function (input, options_list, sort) {
|
||||
frappe.ui.form.add_options = function (input, options_list, sort, doctype) {
|
||||
let $select = $(input);
|
||||
if (!Array.isArray(options_list)) {
|
||||
return $select;
|
||||
}
|
||||
|
||||
let options = options_list.map((raw_option) => parse_option(raw_option));
|
||||
let options = options_list.map((raw_option) => parse_option(raw_option, doctype));
|
||||
if (sort) {
|
||||
options = options.sort((a, b) => cstr(a.label).localeCompare(cstr(b.label)));
|
||||
}
|
||||
|
|
@ -150,7 +155,7 @@ frappe.ui.form.add_options = function (input, options_list, sort) {
|
|||
};
|
||||
})(jQuery);
|
||||
|
||||
function parse_option(v) {
|
||||
function parse_option(v, doctype) {
|
||||
let value = null;
|
||||
let label = null;
|
||||
let is_disabled = false;
|
||||
|
|
@ -164,10 +169,10 @@ function parse_option(v) {
|
|||
|
||||
if (is_value_null && is_label_null && typeof v !== "object") {
|
||||
value = v;
|
||||
label = __(v);
|
||||
label = __(v, null, doctype);
|
||||
} else {
|
||||
value = is_value_null ? "" : v.value;
|
||||
label = is_label_null ? __(value) : __(v.label);
|
||||
label = is_label_null ? __(value, null, doctype) : __(v.label, null, doctype);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue