diff --git a/source/UI/js/Form/ArrayEditable.js b/source/UI/js/Form/ArrayEditable.js index 825af5f0..47ca4f99 100644 --- a/source/UI/js/Form/ArrayEditable.js +++ b/source/UI/js/Form/ArrayEditable.js @@ -82,7 +82,9 @@ Ox.ArrayEditable = function(options, self) { .addClass('OxArrayEditable OxArrayEditable' + Ox.toTitleCase(self.options.type)) .css({width: self.options.width - (self.options.type == 'input' ? 8 : 0) + 'px'}) // 2 x 4 px padding .bindEvent({ - key_delete: deleteItem, + key_delete: function() { + deleteItem(); + }, key_enter: function() { // make sure the newline does // not end up in the textarea @@ -114,13 +116,13 @@ Ox.ArrayEditable = function(options, self) { self.selected = getSelectedPosition(); - function deleteItem() { + function deleteItem(id) { + id = id || self.options.selected; + var position = Ox.getIndexById(self.options.items, id) if (self.options.editable) { - self.options.items.splice(self.selected, 1); + self.options.items.splice(position, 1); renderItems(); - that.triggerEvent('delete', { - id: self.options.selected - }); + that.triggerEvent('delete', {id: id}); self.editing = false; self.selected = -1; self.options.selected = ''; @@ -359,7 +361,9 @@ Ox.ArrayEditable = function(options, self) { function submitItem(position, value) { var item = self.options.items[position]; if (value === '') { - deleteItem(); + // submit may have been triggered by selecting another item, + // so don't delete the selected one + deleteItem(item.id); } else { that.triggerEvent(item.value === value ? 'blur' : 'submit', { id: item.id,