Merge pull request #38 from scott1702/feature/multi-page-forms-v2

Focus on new field when it gets added
This commit is contained in:
Christopher Pitt 2015-08-18 08:22:05 +12:00
commit 7a9cc60cc0

View File

@ -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));