diff --git a/modules/ui/combobox.js b/modules/ui/combobox.js index a3eb653de..030600733 100644 --- a/modules/ui/combobox.js +++ b/modules/ui/combobox.js @@ -21,7 +21,7 @@ import { utilRebind, utilTriggerEvent } from '../util'; var _comboTimerID; export function uiCombobox(context) { - var dispatch = d3_dispatch('accept'); + var dispatch = d3_dispatch('accept', 'cancel'); var container = context.container(); var _suggestions = []; var _values = []; @@ -183,6 +183,9 @@ export function uiCombobox(context) { function keyup() { switch (d3_event.keyCode) { case 27: // ⎋ Escape + container.selectAll('.combobox-option.selected').each(function (d) { + dispatch.call('cancel', this, d); + }); hide(); break; diff --git a/modules/ui/fields/localized.js b/modules/ui/fields/localized.js index 6cf0e58d0..227035dc9 100644 --- a/modules/ui/fields/localized.js +++ b/modules/ui/fields/localized.js @@ -159,6 +159,13 @@ export function uiFieldLocalized(field, context) { 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 }); + }) ); } }