From bfe6ef015841b606ab7123acb8b04ec67023a043 Mon Sep 17 00:00:00 2001 From: scott1702 Date: Mon, 17 Aug 2015 16:39:16 +1200 Subject: [PATCH] focus on new field when added --- javascript/FieldEditor.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/javascript/FieldEditor.js b/javascript/FieldEditor.js index 5c313c5..a336461 100644 --- a/javascript/FieldEditor.js +++ b/javascript/FieldEditor.js @@ -39,5 +39,33 @@ this._super(); } }); + + // When new fields are added.. + $('.uf-field-editor .ss-gridfield-buttonrow .action').entwine({ + onclick: function (e) { + this._super(e); + + this.trigger('addnewinline'); + } + }); + + $('.uf-field-editor').entwine({ + onmatch: function () { + var self = this; + + // When the 'Add field' button is clicked set a one time listener. + // When the GridField is reloaded focus on the newly added field. + this.on('addnewinline', function () { + self.one('reload', function () { + //If fieldgroup, focus on the start marker + if ($('.uf-field-editor .ss-gridfield-item').last().attr('data-class') === 'EditableFieldGroupEnd') { + $('.uf-field-editor .ss-gridfield-item').last().prev().find('.col-Title input').focus(); + } else { + $('.uf-field-editor .ss-gridfield-item:last-child .col-Title input').focus(); + } + }); + }); + } + }); }); }(jQuery));