diff --git a/InvenTree/templates/js/forms.js b/InvenTree/templates/js/forms.js index d372b10db2..5bee4f57a6 100644 --- a/InvenTree/templates/js/forms.js +++ b/InvenTree/templates/js/forms.js @@ -237,6 +237,11 @@ function constructForm(url, options) { // Default HTTP method options.method = options.method || 'PATCH'; + // Create a new modal if one does not exists + if (!options.modal) { + options.modal = createNewModal(); + } + // Request OPTIONS endpoint from the API getApiEndpointOptions(url, function(OPTIONS) { @@ -413,6 +418,7 @@ function constructFormBody(fields, options) { insertConfirmButton(options); } + // Display the modal $(modal).modal('show'); updateFieldValues(fields, options); @@ -433,7 +439,6 @@ function constructFormBody(fields, options) { modalShowSubmitButton(modal, true); - $(modal).off('click', '#modal-form-submit'); $(modal).on('click', '#modal-form-submit', function() { submitFormData(fields, options); @@ -1163,6 +1168,7 @@ function constructField(name, parameters, options) { case 'float': case 'decimal': case 'related field': + case 'date': extra = true; break; default: diff --git a/InvenTree/templates/js/modals.js b/InvenTree/templates/js/modals.js index 75e0f3672a..ddce2fe109 100644 --- a/InvenTree/templates/js/modals.js +++ b/InvenTree/templates/js/modals.js @@ -1,5 +1,58 @@ {% load i18n %} + +/* + * Create and display a new modal dialog + */ +function createNewModal(options={}) { + + var id = options.id || 0; + + // Always increment the ID of the modal + id += 1; + + var html = ` +
+ `; + + $('body').append(html); + + var modal_name = `#modal-form-${id}`; + + // Automatically remove the modal when it is deleted! + $(modal_name).on('hidden.bs.modal', function(e) { + $(modal_name).remove(); + }); + + // Return the "name" of the modal + return modal_name; +} + + function makeOption(text, value, title) { /* Format an option for a select element */