diff --git a/frappe/public/js/frappe/form/controls/multiselect.js b/frappe/public/js/frappe/form/controls/multiselect.js index ae6a7a124e..fc5cb05010 100644 --- a/frappe/public/js/frappe/form/controls/multiselect.js +++ b/frappe/public/js/frappe/form/controls/multiselect.js @@ -32,6 +32,31 @@ frappe.ui.form.ControlMultiSelect = frappe.ui.form.ControlAutocomplete.extend({ }); }, + get_value() { + let data = this._super(); + // find value of label from option list and return actual value string + if (this.df.options[0].label) { + data = data.split(',').map(op => op.trim()); + data = data.map(val => { + let option = this.df.options.find(op => op.label === val); + return option ? option.value : null; + }).filter(n => n != null).join(', '); + } + return data; + }, + + set_formatted_input(value) { + if (!value) return; + // find label of value from option list and set from it as input + if (this.df.options[0].label) { + value = value.split(',').map(d => d.trim()).map(val => { + let option = this.df.options.find(op => op.value === val); + return option ? option.label : val; + }).filter(n => n != null).join(', '); + } + this._super(value); + }, + get_values() { const value = this.get_value() || ''; const values = value.split(/\s*,\s*/).filter(d => d);