fix selection after deleting empty-value annotation by selecting another one

This commit is contained in:
rlx 2018-11-06 17:15:40 +01:00
parent 8d7c5dd4d3
commit 7d178278c5

View file

@ -117,6 +117,8 @@ Ox.ArrayEditable = function(options, self) {
self.selected = getSelectedPosition(); self.selected = getSelectedPosition();
function deleteItem(id) { function deleteItem(id) {
// it is possible to delete an (empty-value) item
// by selecting another one
id = id || self.options.selected; id = id || self.options.selected;
var position = Ox.getIndexById(self.options.items, id) var position = Ox.getIndexById(self.options.items, id)
if (self.options.editable) { if (self.options.editable) {
@ -124,8 +126,12 @@ Ox.ArrayEditable = function(options, self) {
renderItems(); renderItems();
that.triggerEvent('delete', {id: id}); that.triggerEvent('delete', {id: id});
self.editing = false; self.editing = false;
self.selected = -1; if (self.options.selected == id) {
self.options.selected = ''; self.selected = -1;
self.options.selected = '';
} else if (self.options.selected) {
self.selected = Ox.getIndexById(self.options.item, self.options.selected)
}
} }
} }
@ -361,8 +367,6 @@ 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 === '') {
// submit may have been triggered by selecting another item,
// so don't delete the selected one
deleteItem(item.id); deleteItem(item.id);
} else { } else {
that.triggerEvent(item.value === value ? 'blur' : 'submit', { that.triggerEvent(item.value === value ? 'blur' : 'submit', {