Merge pull request #6947 from surajshetty3416/fix-multiselect

fix: Add custom get_value to multiselect
This commit is contained in:
Rushabh Mehta 2019-02-18 11:35:37 +05:30 committed by GitHub
commit dcc3d41d43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);