diff --git a/javascript/GridField.js b/javascript/GridField.js index c94e15713..2ea3671e4 100644 --- a/javascript/GridField.js +++ b/javascript/GridField.js @@ -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);