Confirm Prompt and Run actions or cancel submit
This article explains how to add a confirmation prompt when the submit button is clicked, which will run a series of actions and then submit the form, only when the user clicks "OK".
- Add a button somewhere on your form and add the actions you want to execute, on submit, to that element. Name it 'submitActions'. This button can later be hidden.
- Add a second button, named "Load Dialog Resources," and add an "Alert" action. This is to ensure the dialog JS/resources are loaded for this form. It will never be used and can be hidden.
- On the submit button, add a custom JS action, using the code below, that will open a prompt, and when result = true (the user clicks ok), runs the actions on the submitActions element created in Step 1.
// This function will receive the field and form objects. function(field,form){ meta.stopafter=true; var submitActionEl = form.getFieldByName('submitActions'); BootstrapDialog.confirm({ title: 'Please Confirm', message: 'Are you sure?', type:BootstrapDialog['TYPE_INFO'], closable: false, draggable: true, btnCancelLabel: 'Cancel', btnOKLabel:'Ok', callback: function(result) { if (result){ // do actions! var submitActionEl = lfform.getFieldByName('submitActions'); submitActionEl.doAction('change',submitActionEl,{e:'change'}) meta.stopafter=false; form.doSubmit(true) }else{ meta.stopafter=true; } } }); }
Running a Prompt to Confirm with actions that Execute After OK is clicked on Single Button Element
The difference, when you want to do this on a Single Button Element, is simply that we add a form.doSubmit() call after OK is clicked and we do not need to the "meta.stopafter=false;" line:
// This function will receive the field and form objects. function(field,form){ BootstrapDialog.confirm({ title: 'Submit for Approval', message: 'Please confirm you have submitted the package and the packageID and template name match and that this template is ready for review?', type:BootstrapDialog['TYPE_INFO'], closable: false, draggable: true, btnCancelLabel: 'Cancel', btnOKLabel:'Ok', callback: function(result) { if (result){ // do js actions (you can also specify another button element with a set of actions // that you want to run vs using code below // form.getFieldByName('submitActions').doAction('change',submitActionEl,{e:'change'}) form.getFieldByName('Template State').setValue('Pending Review') // submit the form form.doSubmit(true) } } }); }
Have more questions? Submit a request
Please sign in to leave a comment.
0 Comments