mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-03 05:48:47 +00:00
Adds option to reload a form after success, rather than dismissing it
This commit is contained in:
parent
010ce48ce0
commit
9f5618a51f
@ -934,16 +934,14 @@ function getFormFieldValue(name, field={}, options={}) {
|
|||||||
*/
|
*/
|
||||||
function handleFormSuccess(response, options) {
|
function handleFormSuccess(response, options) {
|
||||||
|
|
||||||
// Close the modal
|
|
||||||
if (!options.preventClose) {
|
|
||||||
// Note: The modal will be deleted automatically after closing
|
|
||||||
$(options.modal).modal('hide');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Display any required messages
|
// Display any required messages
|
||||||
// Should we show alerts immediately or cache them?
|
// Should we show alerts immediately or cache them?
|
||||||
var cache = (options.follow && response.url) || options.redirect || options.reload;
|
var cache = (options.follow && response.url) || options.redirect || options.reload;
|
||||||
|
|
||||||
|
if (options.reloadFormAfterSuccess) {
|
||||||
|
cache = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Display any messages
|
// Display any messages
|
||||||
if (response && (response.success || options.successMessage)) {
|
if (response && (response.success || options.successMessage)) {
|
||||||
showAlertOrCache(response.success || options.successMessage, cache, {style: 'success'});
|
showAlertOrCache(response.success || options.successMessage, cache, {style: 'success'});
|
||||||
@ -966,15 +964,36 @@ function handleFormSuccess(response, options) {
|
|||||||
options.onSuccess(response, options);
|
options.onSuccess(response, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.follow && response.url) {
|
if (options.reloadFormAfterSuccess) {
|
||||||
// Follow the returned URL
|
// Instead of closing the form and going somewhere else,
|
||||||
window.location.href = response.url;
|
// reload (empty) the form so the user can input more data
|
||||||
} else if (options.reload) {
|
|
||||||
// Reload the current page
|
// Reset the status of the "submit" button
|
||||||
location.reload();
|
if (options.modal) {
|
||||||
} else if (options.redirect) {
|
$(options.modal).find('#modal-form-submit').prop('disabled', false);
|
||||||
// Redirect to a specified URL
|
}
|
||||||
window.location.href = options.redirect;
|
|
||||||
|
// Remove any error flags from the form
|
||||||
|
clearFormErrors(options);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// Close the modal
|
||||||
|
if (!options.preventClose) {
|
||||||
|
// Note: The modal will be deleted automatically after closing
|
||||||
|
$(options.modal).modal('hide');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.follow && response.url) {
|
||||||
|
// Follow the returned URL
|
||||||
|
window.location.href = response.url;
|
||||||
|
} else if (options.reload) {
|
||||||
|
// Reload the current page
|
||||||
|
location.reload();
|
||||||
|
} else if (options.redirect) {
|
||||||
|
// Redirect to a specified URL
|
||||||
|
window.location.href = options.redirect;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -989,6 +1008,8 @@ function clearFormErrors(options={}) {
|
|||||||
// Remove the individual error messages
|
// Remove the individual error messages
|
||||||
$(options.modal).find('.form-error-message').remove();
|
$(options.modal).find('.form-error-message').remove();
|
||||||
|
|
||||||
|
$(options.modal).find('.modal-content').removeClass('modal-error');
|
||||||
|
|
||||||
// Remove the "has error" class
|
// Remove the "has error" class
|
||||||
$(options.modal).find('.form-field-error').removeClass('form-field-error');
|
$(options.modal).find('.form-field-error').removeClass('form-field-error');
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user