mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Allow custom code to be run on form submission
This commit is contained in:
parent
c045a3b6f6
commit
9e4bc274cf
@ -444,12 +444,10 @@ function constructFormBody(fields, options) {
|
||||
$(modal).find('#form-content').html(html);
|
||||
|
||||
if (options.preFormContent) {
|
||||
console.log('pre form content', options.preFormContent);
|
||||
$(modal).find('#pre-form-content').html(options.preFormContent);
|
||||
}
|
||||
|
||||
if (options.postFormContent) {
|
||||
console.log('post form content', options.postFormContent);
|
||||
$(modal).find('#post-form-content').html(options.postFormContent);
|
||||
}
|
||||
|
||||
@ -484,7 +482,21 @@ function constructFormBody(fields, options) {
|
||||
|
||||
$(modal).on('click', '#modal-form-submit', function() {
|
||||
|
||||
submitFormData(fields, options);
|
||||
// Immediately disable the "submit" button,
|
||||
// to prevent the form being submitted multiple times!
|
||||
$(options.modal).find('#modal-form-submit').prop('disabled', true);
|
||||
|
||||
// Run custom code before normal form submission
|
||||
if (options.beforeSubmit) {
|
||||
options.beforeSubmit(fields, options);
|
||||
}
|
||||
|
||||
// Run custom code instead of normal form submission
|
||||
if (options.onSubmit) {
|
||||
options.onSubmit(fields, options);
|
||||
} else {
|
||||
submitFormData(fields, options);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -521,10 +533,6 @@ function insertConfirmButton(options) {
|
||||
*/
|
||||
function submitFormData(fields, options) {
|
||||
|
||||
// Immediately disable the "submit" button,
|
||||
// to prevent the form being submitted multiple times!
|
||||
$(options.modal).find('#modal-form-submit').prop('disabled', true);
|
||||
|
||||
// Form data to be uploaded to the server
|
||||
// Only used if file / image upload is required
|
||||
var form_data = new FormData();
|
||||
|
@ -136,6 +136,9 @@ function adjustStock(items, options={}) {
|
||||
preFormContent: html,
|
||||
confirm: true,
|
||||
modal: modal,
|
||||
onSubmit: function(fields, options) {
|
||||
console.log("submit!");
|
||||
}
|
||||
});
|
||||
|
||||
// Attach callbacks for the action buttons
|
||||
|
Loading…
Reference in New Issue
Block a user