diff --git a/data/presets/README.md b/data/presets/README.md index 6a92919e8..ed3c0469a 100644 --- a/data/presets/README.md +++ b/data/presets/README.md @@ -63,9 +63,10 @@ In which `type` is the fields's type. Valid field types are * textarea * radio * combo -* check * address -* defaultcheck - a checkbox that can be yes, no, or null - not filled +* check - a tri-state checkbox: yes, no, or unknown (no tag) +* defaultcheck - a boolean checkbox where checked produces a `*=yes` tag and + unchecked produces no tag The `key` property names the OSM key that the field will edit. Alternatively, for compound fields like `address`, you can specify an array of keys in the `keys` diff --git a/index.html b/index.html index 3d43d56a4..fec78cf5c 100644 --- a/index.html +++ b/index.html @@ -114,7 +114,6 @@ - diff --git a/js/id/ui/preset/check.js b/js/id/ui/preset/check.js index dd7bce7da..2badb14fc 100644 --- a/js/id/ui/preset/check.js +++ b/js/id/ui/preset/check.js @@ -1,6 +1,9 @@ -iD.ui.preset.check = function(field) { +iD.ui.preset.check = +iD.ui.preset.defaultcheck = function(field) { var event = d3.dispatch('change'), - values = [undefined, 'yes', 'no'], + values = field.type === 'check' ? + [undefined, 'yes', 'no'] : + [undefined, 'yes'], value, box, text, @@ -16,7 +19,7 @@ iD.ui.preset.check = function(field) { .attr('class', 'preset-input-wrap'); enter.append('input') - .property('indeterminate', true) + .property('indeterminate', field.type === 'check') .attr('type', 'checkbox') .attr('id', 'preset-input-' + field.id); @@ -27,7 +30,7 @@ iD.ui.preset.check = function(field) { box = label.select('input') .on('click', function() { var t = {}; - t[field.key] = values[(values.indexOf(value) + 1) % 3]; + t[field.key] = values[(values.indexOf(value) + 1) % values.length]; event.change(t); d3.event.stopPropagation(); }); @@ -37,9 +40,10 @@ iD.ui.preset.check = function(field) { check.tags = function(tags) { value = tags[field.key]; - box.property('indeterminate', !value); + box.property('indeterminate', field.type === 'check' && !value); box.property('checked', value === 'yes'); - text.text(value ? t('inspector.check.' + value, {default: value}) : t('inspector.unknown')); + text.text(value ? t('inspector.check.' + value, {default: value}) : + field.type === 'check' ? t('inspector.unknown') : t('inspector.check.no')); label.classed('set', !!value); }; diff --git a/js/id/ui/preset/defaultcheck.js b/js/id/ui/preset/defaultcheck.js deleted file mode 100644 index c9638c349..000000000 --- a/js/id/ui/preset/defaultcheck.js +++ /dev/null @@ -1,30 +0,0 @@ -iD.ui.preset.defaultcheck = function(field) { - var event = d3.dispatch('change'), - input; - - function check(selection) { - input = selection.selectAll('input') - .data([0]); - - input.enter().append('input') - .attr('type', 'checkbox') - .attr('id', 'preset-input-' + field.id); - - input - .on('change', function() { - var t = {}; - t[field.key] = input.property('checked') ? field.value || 'yes' : undefined; - event.change(t); - }); - } - - check.tags = function(tags) { - input.property('checked', !!tags[field.key] && tags[field.key] !== 'no'); - }; - - check.focus = function() { - input.node().focus(); - }; - - return d3.rebind(check, event, 'on'); -};