Add option to focus on a particular field when launching

This commit is contained in:
Oliver 2021-07-02 19:40:02 +10:00
parent c7f834e547
commit 746a0210fe
2 changed files with 14 additions and 1 deletions

View File

@ -227,6 +227,8 @@ function constructDeleteForm(fields, options) {
* options:
* - method: The HTTP method e.g. 'PUT', 'POST', 'DELETE' (default='PATCH')
* - title: The form title
* - submitText: Text for the "submit" button
* - closeText: Text for the "close" button
* - fields: list of fields to display, with the following options
* - filters: API query filters
* - onEdit: callback when field is edited
@ -237,6 +239,7 @@ function constructDeleteForm(fields, options) {
* - hidden: Set to true to hide the field
* - icon: font-awesome icon to display before the field
* - prefix: Custom HTML prefix to display before the field
* - focus: Name of field to focus on when modal is displayed
* - preventClose: Set to true to prevent form from closing on success
* - onSuccess: callback function when form action is successful
* - follow: If a 'url' is provided by the API on success, redirect to it

View File

@ -3,6 +3,12 @@
/*
* Create and display a new modal dialog
*
* options:
* - title: Form title to render
* - submitText: Text to render on 'submit' button (default = "Submit")
* - closeText: Text to render on 'close' button (default = "Cancel")
* - focus: Name of field to focus on after launching
*/
function createNewModal(options={}) {
@ -11,8 +17,8 @@ function createNewModal(options={}) {
// Check out what modal forms are already being displayed
$('.inventree-modal').each(function() {
var split = this.id.split('-');
console.log('existing form:', split);
var modal_id = parseInt(split[2]);
if (modal_id >= id) {
@ -64,6 +70,10 @@ function createNewModal(options={}) {
$(modal_name).on('shown.bs.modal', function() {
$(modal_name + ' .modal-form-content').scrollTop(0);
if (options.focus) {
getFieldByName(modal_name, options.focus).focus();
}
});
// Automatically remove the modal when it is deleted!