mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-01 04:56:45 +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);
|
$(modal).find('#form-content').html(html);
|
||||||
|
|
||||||
if (options.preFormContent) {
|
if (options.preFormContent) {
|
||||||
console.log('pre form content', options.preFormContent);
|
|
||||||
$(modal).find('#pre-form-content').html(options.preFormContent);
|
$(modal).find('#pre-form-content').html(options.preFormContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.postFormContent) {
|
if (options.postFormContent) {
|
||||||
console.log('post form content', options.postFormContent);
|
|
||||||
$(modal).find('#post-form-content').html(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() {
|
$(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) {
|
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
|
// Form data to be uploaded to the server
|
||||||
// Only used if file / image upload is required
|
// Only used if file / image upload is required
|
||||||
var form_data = new FormData();
|
var form_data = new FormData();
|
||||||
|
@ -136,6 +136,9 @@ function adjustStock(items, options={}) {
|
|||||||
preFormContent: html,
|
preFormContent: html,
|
||||||
confirm: true,
|
confirm: true,
|
||||||
modal: modal,
|
modal: modal,
|
||||||
|
onSubmit: function(fields, options) {
|
||||||
|
console.log("submit!");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Attach callbacks for the action buttons
|
// Attach callbacks for the action buttons
|
||||||
|
Loading…
x
Reference in New Issue
Block a user