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.
This commit is contained in:
John Firebaugh
2013-05-25 13:20:43 -07:00
parent 79737d2cd0
commit 46f41fa4f4
12 changed files with 53 additions and 51 deletions

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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
});
}

View File

@@ -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');

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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')

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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 || ''));
}

View File

@@ -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(_) {