Commit 63764a7d authored by ChaosKid42's avatar ChaosKid42 Committed by JC Brand

fix selected values in list-multi form fields (#1101)

parent a33b451b
...@@ -814,5 +814,21 @@ ...@@ -814,5 +814,21 @@
const replacement = 'geo:$1,$2'; const replacement = 'geo:$1,$2';
return text.replace(_converse.geouri_regex, replacement); return text.replace(_converse.geouri_regex, replacement);
}; };
u.getSelectValues = function(select) {
var result = [];
var options = select && select.options;
var opt;
for (var i=0, iLen=options.length; i<iLen; i++) {
opt = options[i];
if (opt.selected) {
result.push(opt.value || opt.text);
}
}
return result;
};
return u; return u;
})); }));
...@@ -58,8 +58,10 @@ ...@@ -58,8 +58,10 @@
let value; let value;
if (field.getAttribute('type') === 'checkbox') { if (field.getAttribute('type') === 'checkbox') {
value = field.checked && 1 || 0; value = field.checked && 1 || 0;
} else if (field.tagName == "textarea") { } else if (field.tagName == "TEXTAREA") {
value = _.filter(field.value.split('\n'), _.trim); value = _.filter(field.value.split('\n'), _.trim);
} else if (field.tagName == "SELECT") {
value = u.getSelectValues(field);
} else { } else {
value = field.value; value = field.value;
} }
...@@ -96,7 +98,7 @@ ...@@ -96,7 +98,7 @@
return tpl_select_option({ return tpl_select_option({
'value': value, 'value': value,
'label': option.getAttribute('label'), 'label': option.getAttribute('label'),
'selected': _.startsWith(values, value), 'selected': values.includes(value),
'required': !_.isNil(field.querySelector('required')) 'required': !_.isNil(field.querySelector('required'))
}) })
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment