fix issue where selecting an annotation with another empty annotation in editing state would delete the newly selected annotation

This commit is contained in:
rlx 2018-11-06 17:07:37 +01:00
parent 222f74d1b5
commit 8d7c5dd4d3

View file

@ -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,