focus on new field when added

This commit is contained in:
scott1702 2015-08-17 16:39:16 +12:00
parent ab79e5cd11
commit bfe6ef0158

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