From 46f41fa4f462f9b88805eb3c8f4881f8fc45b491 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Sat, 25 May 2013 13:20:43 -0700 Subject: [PATCH] Use undefined value to remove a key rather than empty string Otherwise it is impossible to tab out of the key input of a new tag row -- since the value is still empty, the tag is removed before you have a chance to enter a value. --- js/id/ui/entity_editor.js | 11 ++++++----- js/id/ui/preset/access.js | 2 +- js/id/ui/preset/address.js | 10 +++++----- js/id/ui/preset/check.js | 7 +++---- js/id/ui/preset/combo.js | 2 +- js/id/ui/preset/input.js | 2 +- js/id/ui/preset/localized.js | 4 ++-- js/id/ui/preset/maxspeed.js | 20 +++++++++---------- js/id/ui/preset/radio.js | 4 ++-- js/id/ui/preset/textarea.js | 2 +- js/id/ui/preset/wikipedia.js | 2 +- js/id/ui/raw_tag_editor.js | 38 +++++++++++++++++++----------------- 12 files changed, 53 insertions(+), 51 deletions(-) diff --git a/js/id/ui/entity_editor.js b/js/id/ui/entity_editor.js index bed9d68b9..ce967b79f 100644 --- a/js/id/ui/entity_editor.js +++ b/js/id/ui/entity_editor.js @@ -99,7 +99,7 @@ iD.ui.EntityEditor = function(context) { .entityID(id)); } else { $body.select('.raw-member-editor') - .style('display', 'none') + .style('display', 'none'); } $body.select('.raw-membership-editor') @@ -122,10 +122,11 @@ iD.ui.EntityEditor = function(context) { } function clean(o) { - var out = {}; - for (var k in o) { - var v = o[k].trim(); - if (v) out[k] = v; + var out = {}, k, v; + for (k in o) { + if (k && (v = o[k]) !== undefined) { + out[k] = v.trim(); + } } return out; } diff --git a/js/id/ui/preset/access.js b/js/id/ui/preset/access.js index 56e568674..adc57522e 100644 --- a/js/id/ui/preset/access.js +++ b/js/id/ui/preset/access.js @@ -45,7 +45,7 @@ iD.ui.preset.access = function(field, context) { function change(d) { var tag = {}; - tag[d] = d3.select(this).property('value'); + tag[d] = d3.select(this).property('value') || undefined; event.change(tag); } diff --git a/js/id/ui/preset/address.js b/js/id/ui/preset/address.js index 7d0cf23f4..ad2657dab 100644 --- a/js/id/ui/preset/address.js +++ b/js/id/ui/preset/address.js @@ -87,11 +87,11 @@ iD.ui.preset.address = function(field, context) { function change() { event.change({ - 'addr:housename': housename.property('value'), - 'addr:housenumber': housenumber.property('value'), - 'addr:street': street.property('value'), - 'addr:city': city.property('value'), - 'addr:postcode': postcode.property('value') + 'addr:housename': housename.property('value') || undefined, + 'addr:housenumber': housenumber.property('value') || undefined, + 'addr:street': street.property('value') || undefined, + 'addr:city': city.property('value') || undefined, + 'addr:postcode': postcode.property('value') || undefined }); } diff --git a/js/id/ui/preset/check.js b/js/id/ui/preset/check.js index 2efbdc028..23772636d 100644 --- a/js/id/ui/preset/check.js +++ b/js/id/ui/preset/check.js @@ -1,7 +1,7 @@ iD.ui.preset.check = function(field) { var event = d3.dispatch('change'), - values = ['', 'yes', 'no'], - value = '', + values = [undefined, 'yes', 'no'], + value, box, text, label; @@ -28,7 +28,6 @@ iD.ui.preset.check = function(field) { .on('click', function() { var t = {}; t[field.key] = values[(values.indexOf(value) + 1) % 3]; - check.tags(t); event.change(t); d3.event.stopPropagation(); }); @@ -37,7 +36,7 @@ iD.ui.preset.check = function(field) { }; check.tags = function(tags) { - value = tags[field.key] || ''; + value = tags[field.key]; box.property('indeterminate', !value); box.property('checked', value === 'yes'); text.text(value || 'unknown'); diff --git a/js/id/ui/preset/combo.js b/js/id/ui/preset/combo.js index 95dd9e47d..c5b7f7c88 100644 --- a/js/id/ui/preset/combo.js +++ b/js/id/ui/preset/combo.js @@ -43,7 +43,7 @@ iD.ui.preset.combo = function(field) { function change() { var t = {}; - t[field.key] = input.property('value').replace(' ', '_'); + t[field.key] = input.property('value').replace(' ', '_') || undefined; event.change(t); } diff --git a/js/id/ui/preset/input.js b/js/id/ui/preset/input.js index 2056a18ed..85846c1b7 100644 --- a/js/id/ui/preset/input.js +++ b/js/id/ui/preset/input.js @@ -53,7 +53,7 @@ iD.ui.preset.url = function(field) { function change() { var t = {}; - t[field.key] = input.property('value'); + t[field.key] = input.property('value') || undefined; event.change(t); } diff --git a/js/id/ui/preset/localized.js b/js/id/ui/preset/localized.js index 6561683f9..eb39b597b 100644 --- a/js/id/ui/preset/localized.js +++ b/js/id/ui/preset/localized.js @@ -47,7 +47,7 @@ iD.ui.preset.localized = function(field, context) { function change() { var t = {}; - t[field.key] = d3.select(this).property('value'); + t[field.key] = d3.select(this).property('value') || undefined; event.change(t); } @@ -131,7 +131,7 @@ iD.ui.preset.localized = function(field, context) { .attr('class', 'minor button-input-action remove') .on('click', function(d) { var t = {}; - t[key(d.lang)] = ''; + t[key(d.lang)] = undefined; event.change(t); d3.select(this.parentNode) .style('top','0') diff --git a/js/id/ui/preset/maxspeed.js b/js/id/ui/preset/maxspeed.js index 926ce7e64..e3210edf5 100644 --- a/js/id/ui/preset/maxspeed.js +++ b/js/id/ui/preset/maxspeed.js @@ -69,18 +69,18 @@ iD.ui.preset.maxspeed = function(field, context) { } function change() { - var value = input.property('value'); - var t = {}; - if (value) { - if (isNaN(value) || !imperial) { - t[field.key] = value; - } else { - t[field.key] = value + ' mph'; - } + var tag = {}, + value = input.property('value'); + + if (!value) { + tag[field.key] = undefined; + } else if (isNaN(value) || !imperial) { + tag[field.key] = value; } else { - t[field.key] = ''; + tag[field.key] = value + ' mph'; } - event.change(t); + + event.change(tag); } maxspeed.tags = function(tags) { diff --git a/js/id/ui/preset/radio.js b/js/id/ui/preset/radio.js index 3af0a8d07..23002ad7c 100644 --- a/js/id/ui/preset/radio.js +++ b/js/id/ui/preset/radio.js @@ -42,13 +42,13 @@ iD.ui.preset.radio = function(field) { function change() { var t = {}; - if (field.key) t[field.key] = null; + if (field.key) t[field.key] = undefined; buttons.each(function(d) { var active = d3.select(this).classed('active'); if (field.key) { if (active) t[field.key] = d; } else { - t[d] = active ? 'yes' : ''; + t[d] = active ? 'yes' : undefined; } }); event.change(t); diff --git a/js/id/ui/preset/textarea.js b/js/id/ui/preset/textarea.js index 83fe0c21c..0fd78955d 100644 --- a/js/id/ui/preset/textarea.js +++ b/js/id/ui/preset/textarea.js @@ -19,7 +19,7 @@ iD.ui.preset.textarea = function(field) { function change() { var t = {}; - t[field.key] = input.property('value'); + t[field.key] = input.property('value') || undefined; event.change(t); } diff --git a/js/id/ui/preset/wikipedia.js b/js/id/ui/preset/wikipedia.js index 6ac4b205d..5306fe611 100644 --- a/js/id/ui/preset/wikipedia.js +++ b/js/id/ui/preset/wikipedia.js @@ -101,7 +101,7 @@ iD.ui.preset.wikipedia = function(field, context) { lang.property('value', language[0]); } - t[field.key] = value ? language[2] + ':' + value : ''; + t[field.key] = value ? language[2] + ':' + value : undefined; event.change(t); link.attr('href', 'http://' + language[2] + '.wikipedia.org/wiki/' + (value || '')); } diff --git a/js/id/ui/raw_tag_editor.js b/js/id/ui/raw_tag_editor.js index ff8886509..4feaf5c1e 100644 --- a/js/id/ui/raw_tag_editor.js +++ b/js/id/ui/raw_tag_editor.js @@ -114,19 +114,6 @@ iD.ui.RawTagEditor = function(context) { $items.exit() .remove(); - function keyChange(d) { - var tag = {}; - tag[this.value] = d.value; - d.key = this.value; // Maintain DOM identity through the subsequent update. - event.change(tag); - } - - function valueChange(d) { - var tag = {}; - tag[d.key] = this.value; - event.change(tag); - } - function pushMore() { if (d3.event.keyCode === 9 && !d3.event.shiftKey && $list.selectAll('li:last-child input.value').node() === this) { @@ -178,16 +165,31 @@ iD.ui.RawTagEditor = function(context) { })); } + function keyChange(d) { + var tag = {}; + tag[d.key] = undefined; + tag[this.value] = d.value; + d.key = this.value; // Maintain DOM identity through the subsequent update. + event.change(tag); + } + + function valueChange(d) { + var tag = {}; + tag[d.key] = this.value; + event.change(tag); + } + + function removeTag(d) { + var tag = {}; + tag[d.key] = undefined; + event.change(tag); + } + function addTag() { tags[''] = ''; content($wrap); $list.selectAll('li:last-child input.key').node().focus(); } - - function removeTag(d) { - tags[d.key] = ''; - event.change(tags); - } } rawTagEditor.preset = function(_) {