Permalink
Browse files

ENHANCEMENT Improved focus handling in GridField

  • Loading branch information...
chillu committed Mar 6, 2012
1 parent dc83ace commit bd1f652fe954c645766a179ff71f57cf1abef861
Showing with 8 additions and 1 deletion.
  1. +8 −1 javascript/GridField.js
View
@@ -6,7 +6,10 @@
* @param {successCallback} callback to call after reloading succeeded.
*/
reload: function(ajaxOpts, successCallback) {
- var self = this, form = this.closest('form'), data = form.find(':input').serializeArray();
+ var self = this, form = this.closest('form'),
+ focusedElName = this.find(':input:focus').attr('name'), // Save focused element for restoring after refresh
+ data = form.find(':input').serializeArray();
+
if(!ajaxOpts) ajaxOpts = {};
if(!ajaxOpts.data) ajaxOpts.data = [];
ajaxOpts.data = ajaxOpts.data.concat(data);
@@ -30,6 +33,10 @@
// of the executing method. Means that it doesn't retrigger the onmatch() on the main container.
self.empty().append($(data).children());
+ // Refocus previously focused element. Useful e.g. for finding+adding
+ // multiple relationships via keyboard.
+ if(focusedElName) self.find(':input[name="' + focusedElName + '"]').focus();
+
form.removeClass('loading');
if(successCallback) successCallback.apply(this, arguments);
self.trigger('reload', self);

0 comments on commit bd1f652

Please sign in to comment.