fix issue where selecting an annotation with another empty annotation in editing state would delete the newly selected annotation
This commit is contained in:
parent
222f74d1b5
commit
8d7c5dd4d3
1 changed files with 11 additions and 7 deletions
|
@ -82,7 +82,9 @@ Ox.ArrayEditable = function(options, self) {
|
||||||
.addClass('OxArrayEditable OxArrayEditable' + Ox.toTitleCase(self.options.type))
|
.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
|
.css({width: self.options.width - (self.options.type == 'input' ? 8 : 0) + 'px'}) // 2 x 4 px padding
|
||||||
.bindEvent({
|
.bindEvent({
|
||||||
key_delete: deleteItem,
|
key_delete: function() {
|
||||||
|
deleteItem();
|
||||||
|
},
|
||||||
key_enter: function() {
|
key_enter: function() {
|
||||||
// make sure the newline does
|
// make sure the newline does
|
||||||
// not end up in the textarea
|
// not end up in the textarea
|
||||||
|
@ -114,13 +116,13 @@ Ox.ArrayEditable = function(options, self) {
|
||||||
|
|
||||||
self.selected = getSelectedPosition();
|
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) {
|
if (self.options.editable) {
|
||||||
self.options.items.splice(self.selected, 1);
|
self.options.items.splice(position, 1);
|
||||||
renderItems();
|
renderItems();
|
||||||
that.triggerEvent('delete', {
|
that.triggerEvent('delete', {id: id});
|
||||||
id: self.options.selected
|
|
||||||
});
|
|
||||||
self.editing = false;
|
self.editing = false;
|
||||||
self.selected = -1;
|
self.selected = -1;
|
||||||
self.options.selected = '';
|
self.options.selected = '';
|
||||||
|
@ -359,7 +361,9 @@ Ox.ArrayEditable = function(options, self) {
|
||||||
function submitItem(position, value) {
|
function submitItem(position, value) {
|
||||||
var item = self.options.items[position];
|
var item = self.options.items[position];
|
||||||
if (value === '') {
|
if (value === '') {
|
||||||
deleteItem();
|
// submit may have been triggered by selecting another item,
|
||||||
|
// so don't delete the selected one
|
||||||
|
deleteItem(item.id);
|
||||||
} else {
|
} else {
|
||||||
that.triggerEvent(item.value === value ? 'blur' : 'submit', {
|
that.triggerEvent(item.value === value ? 'blur' : 'submit', {
|
||||||
id: item.id,
|
id: item.id,
|
||||||
|
|
Loading…
Reference in a new issue