Fix keyboard control of switches in the column grid. Fixes #1394

pull/3/head
Murtuza Zabuawala 2017-01-08 04:00:09 +00:00 committed by Dave Page
parent a33ee2ae32
commit 879a6bef53
2 changed files with 41 additions and 4 deletions

View File

@ -248,17 +248,27 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
this.$el.removeClass('editor');
// Once user have selected a value
// we can shift to next cell if it is editable
var el_length_cell = this.$el.next();
var next_cell, length_cell = this.$el.next(),
not_null_cell = this.$el.next().next().next();
// Add delay so that Select2 cell tab event is captured
// first before triggerring backgrid:edited event.
setTimeout(function() {
if(el_length_cell && el_length_cell.hasClass('editable') && e) {
// First check Length column if it is disable then goto
// Not Null column
if(length_cell && length_cell.hasClass('editable') && e) {
next_cell = length_cell;
} else if(not_null_cell && not_null_cell.hasClass('editable') && e) {
next_cell = not_null_cell;
}
if(next_cell) {
e.preventDefault();
e.stopPropagation();
var command = new Backgrid.Command({key: "Tab", keyCode: 9, which: 9});
self.model.trigger("backgrid:edited", self.model, self.column,
command);
el_length_cell.focus();
next_cell.focus();
}
}, 20);
}

View File

@ -352,6 +352,7 @@
enterEditMode: function() {
this.$el.addClass('editor');
$(this.$el.find('input')).focus();
},
exitEditMode: function() {
@ -372,7 +373,7 @@
},
render: function () {
var col = _.defaults(this.column.toJSON(), this.defaults),
var self = this, col = _.defaults(this.column.toJSON(), this.defaults),
attributes = this.model.toJSON(),
attrArr = col.name.split('.'),
name = attrArr.shift(),
@ -401,6 +402,32 @@
this.defaults.options
));
// Listen for Tab key
this.$el.on('keydown', function(e) {
var gotoCell;
if(e.keyCode == 9) {
// go to Next Cell & if Shift is also pressed go to Previous Cell
gotoCell = e.shiftKey ? self.$el.prev() : self.$el.next();
}
if(gotoCell) {
setTimeout(function() {
if(gotoCell.hasClass('editable')) {
e.preventDefault();
e.stopPropagation();
var command = new Backgrid.Command({
key: "Tab", keyCode: 9,
which: 9, shiftKey: e.shiftKey
});
self.model.trigger("backgrid:edited", self.model,
self.column, command);
gotoCell.focus();
}
}, 20);
}
});
this.delegateEvents();
return this;