mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-21 07:46:58 +02:00
Make sure all combo event listeners can handle accept/cancel w/o datum
(re: #5637, re: #5618) This can happen if the user enters a value that is not matched to one of the combo suggestions. Also make sure to set `this` to the input field. It might not be already if the event was triggered from a keypress instead of a click.
This commit is contained in:
@@ -147,25 +147,8 @@ export function uiFieldLocalized(field, context) {
|
||||
input
|
||||
.call(brandCombo
|
||||
.fetcher(fetchBrandNames(preset, allSuggestions))
|
||||
.on('accept', function(d) {
|
||||
var entity = context.entity(_entity.id); // get latest
|
||||
var tags = entity.tags;
|
||||
var geometry = entity.geometry(context.graph());
|
||||
var removed = preset.unsetTags(tags, geometry);
|
||||
for (var k in tags) {
|
||||
tags[k] = removed[k]; // set removed tags to `undefined`
|
||||
}
|
||||
tags = d.suggestion.setTags(tags, geometry);
|
||||
utilGetSetValue(input, tags.name);
|
||||
dispatch.call('change', this, tags);
|
||||
})
|
||||
.on('cancel', function() {
|
||||
// user hit escape, remove whatever is after the '-'
|
||||
var name = utilGetSetValue(input);
|
||||
name = name.split('-', 2)[0].trim();
|
||||
utilGetSetValue(input, name);
|
||||
dispatch.call('change', this, { name: name });
|
||||
})
|
||||
.on('accept', acceptBrand)
|
||||
.on('cancel', cancelBrand)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -216,6 +199,34 @@ export function uiFieldLocalized(field, context) {
|
||||
|
||||
|
||||
|
||||
function acceptBrand(d) {
|
||||
if (!d) {
|
||||
cancelBrand();
|
||||
return;
|
||||
}
|
||||
|
||||
var entity = context.entity(_entity.id); // get latest
|
||||
var tags = entity.tags;
|
||||
var geometry = entity.geometry(context.graph());
|
||||
var removed = preset.unsetTags(tags, geometry);
|
||||
for (var k in tags) {
|
||||
tags[k] = removed[k]; // set removed tags to `undefined`
|
||||
}
|
||||
tags = d.suggestion.setTags(tags, geometry);
|
||||
utilGetSetValue(input, tags.name);
|
||||
dispatch.call('change', this, tags);
|
||||
}
|
||||
|
||||
|
||||
function cancelBrand() {
|
||||
// user hit escape, remove whatever is after the ' - '
|
||||
var name = utilGetSetValue(input);
|
||||
name = name.split(' - ', 2)[0].trim();
|
||||
utilGetSetValue(input, name);
|
||||
dispatch.call('change', this, { name: name });
|
||||
}
|
||||
|
||||
|
||||
function fetchBrandNames(preset, suggestions) {
|
||||
var pTag = preset.id.split('/', 2);
|
||||
var pKey = pTag[0];
|
||||
|
||||
Reference in New Issue
Block a user