Skip to content

Commit

Permalink
Treat multicombo values other than 'no' and '' as if they are set
Browse files Browse the repository at this point in the history
And don't set a multicombo value to 'yes' if it already has a non-'no' value
(closes #5291)
  • Loading branch information
bhousel committed Sep 4, 2018
1 parent 91872d7 commit 71592f3
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions modules/ui/fields/combo.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,24 @@ export function uiFieldCombo(field, context) {
if (!val) return;
container.classed('active', false);
utilGetSetValue(input, '');

if (isMulti) {
field.keys.push(field.key + val);
t[field.key + val] = 'yes';
var key = field.key + val;
if (_entity) {
// don't set a multicombo value to 'yes' if it already has a non-'no' value
// e.g. `language:de=main`
var old = _entity.tags[key] || '';
if (old && old.toLowerCase() !== 'no') return;
}
field.keys.push(key);
t[key] = 'yes';

} else if (isSemi) {
var arr = _multiData.map(function(d) { return d.key; });
arr.push(val);
t[field.key] = _compact(_uniq(arr)).join(';');
}

window.setTimeout(function() { input.node().focus(); }, 10);

} else {
Expand Down Expand Up @@ -332,25 +342,27 @@ export function uiFieldCombo(field, context) {

if (isMulti) {
// Build _multiData array containing keys already set..
Object.keys(tags).forEach(function(key) {
if (key.indexOf(field.key) !== 0 || tags[key].toLowerCase() !== 'yes') return;
for (var k in tags) {
if (k.indexOf(field.key) !== 0) continue;
var v = (tags[k] || '').toLowerCase();
if (v === '' || v === 'no') continue;

var suffix = key.substring(field.key.length);
var suffix = k.substring(field.key.length);
_multiData.push({
key: key,
key: k,
value: displayValue(suffix)
});
});
}

// Set keys for form-field modified (needed for undo and reset buttons)..
field.keys = _map(_multiData, 'key');

} else if (isSemi) {
var arr = _compact(_uniq((tags[field.key] || '').split(';')));
_multiData = arr.map(function(key) {
_multiData = arr.map(function(k) {
return {
key: key,
value: displayValue(key)
key: k,
value: displayValue(k)
};
});
}
Expand Down

0 comments on commit 71592f3

Please sign in to comment.