Set field.keys so that delete/undo buttons work

For multiselect fields,
field.key should have a ':' on the end of it - we use as the prefix, not the real key
field.keys should contain the array of real keys being modified

see https://github.com/openstreetmap/iD/blob/master/js/id/ui/preset.js#L17-L45

The address field preset works like this also..
It contains an array of key.fields for all the subfields that might be set.
For multiselect fields, we don't know ahead of time what all the subfields are,
so we append to the list in `change()` and rebuild list in `tags()`
This commit is contained in:
Bryan Housel
2016-04-22 21:22:24 -04:00
parent 9d8626a330
commit 1a9c111d78
4 changed files with 20 additions and 14 deletions
+1 -1
View File
@@ -774,7 +774,7 @@ en:
# 'railway=*'
label: Type
recycling/recycling_choices:
# 'recycling=*'
# 'recycling:=*'
label: Accepts
ref:
# 'ref=*'
+1 -1
View File
@@ -1021,7 +1021,7 @@
"label": "Type"
},
"recycling/recycling_choices": {
"key": "recycling",
"key": "recycling:",
"type": "multiselect",
"label": "Accepts"
},
@@ -1,5 +1,5 @@
{
"key": "recycling",
"key": "recycling:",
"type": "multiselect",
"label": "Accepts"
}
+17 -11
View File
@@ -9,7 +9,10 @@ iD.ui.preset.multiselect = function(field, context) {
input,
isInitialized;
field.key += ':';
// ensure field.key ends with a ':'
if (field.key.match(/.*:$/) === null) {
field.key += ':';
}
function getOptStringKey(val) {
if (optstrings) {
@@ -35,7 +38,7 @@ iD.ui.preset.multiselect = function(field, context) {
bObj[obj.key] = obj;
});
// Return all elements in a, unless in b
return a.filter(function(obj){
return a.filter(function(obj) {
return !(obj.key in bObj);
});
}
@@ -71,10 +74,10 @@ iD.ui.preset.multiselect = function(field, context) {
.each(function() {
if (optstrings) {
strings = Object.keys(optstrings).map(function(k) {
return {
key: k,
value: field.t('options.' + k, { 'default': optstrings[k] })
};
return {
key: k,
value: field.t('options.' + k, { 'default': optstrings[k] })
};
});
dispatch.init();
isInitialized = true;
@@ -111,12 +114,12 @@ iD.ui.preset.multiselect = function(field, context) {
function update(data) {
var chips = multiselectContainer.selectAll('.chips').data(data);
var chip = chips.enter()
var enter = chips.enter()
.insert('li', 'input')
.attr('class', 'chips');
chip.append('span');
chip.append('a');
enter.append('span');
enter.append('a');
chips.select('span').text(function(d) {return d.value;});
@@ -130,8 +133,8 @@ iD.ui.preset.multiselect = function(field, context) {
function comboValues(d) {
return {
value: d.value,
title: d.value
value: d.value,
title: d.value
};
}
@@ -142,6 +145,7 @@ iD.ui.preset.multiselect = function(field, context) {
var t = {};
t[field.key + key] = 'yes';
input.value('');
field.keys.push(field.key + key);
dispatch.change(t);
}
}
@@ -175,6 +179,8 @@ iD.ui.preset.multiselect = function(field, context) {
}
});
field.keys = _.map(_.pluck(tagsData, 'key'), function(v) { return field.key + v; });
update(tagsData);
if (isInitialized) {