spmodal in Catalog CLient Script onsubmit for Agree and Cancel buttons

mattmm
Kilo Sage

HI, Firstly if there's an easier way to achieve this than the way I am doing please let me know.

I have a Form (Catalog Item) in my portal that is essentially a Confidentiality Agreement that requires Either Agreement or Cancel to signify a users Agreement to the CA.

  1. On Submit I want it to pop up an Agree or Cancel dialog box
  2. On Agree (not submit) I need it to still create an RITM and kick off my Workflow, Approval process etc.
  3. On Cancel (or if the dialog is closed) I need it to return to the form (Although Ideally if someone cancels it would be good to have another message come up advising the person had cancelled this and it returns to the homepage, but that might be for another question).

I am doing this by using an OnSubmit Catalog Client Script within my Catalog Item.

My unfinished code below submits a ticket for both options instead of cancelling when I require. How do I cancel as stated above when someone chooses cancel or closes the dialog box? Any help would be greatly appreciated!

function onSubmit() {
// we will use the g_form JS object here to store a true/false value for us
// telling us whether the user has already clicked No
if (g_form._hasConfirmed == true) {
// this means they have already confirmed via the spModal
// so no need to check again
return true;
}
if (typeof spModal != 'undefined') {
// this is SP, none of the below
// will work on native UI FYI
spModal.open({
message: 'By clicking the Agree button below you confirm you have read, understood , and agree with the Confidentiality Agreement', 
title: 'Confidentiality Agreement',
buttons: [ 
{label:'✘ Cancel', cancel: true},
{label:'✔ Agree', primary: true}
]
}).then(function(confirmed) {
if (confirmed) {
location.href="sp?id=requests";
return true;
} 
});}
}
1 ACCEPTED SOLUTION

mattmm
Kilo Sage

So I ended up doing this a little differently for anyone who finds their way here.  I decided to create a catalog item that had one Field after the Confidentiality Agreement. Within that field I had two values, Agree or Cancel.

If someone chose Agree and Submit it submitted as normal and created a Request and Requested Item that went off on a  Approval workflow.

If they chose Cancel it would have an alert message saying "You have chosen to Cancel this agreement. No Acceptance or Approval request will be submitted."

 

I did this by creating an OnSubmit Catalog Client Script on my Catalog Item with the following code:

 function onSubmit() {

{
var disagree = g_form.getValue('insert_your_variable_value_here'); //Get the value from the select box

	if (disagree == 'Cancel') { //If Disagree is selected from the select box.

{

alert("You have chosen to Cancel this agreement. No Acceptance or Approval request will be submitted.");

return false;
}
}
return true; 
}
}

View solution in original post

4 REPLIES 4

Thanks Raf, that's actually my original post a while back, but the problem I had here was that my message, is more of a document (that is, it contains HTML, bullet points, Headings etc. and is about a page, two pages long). To mitigate this I thought I'd just include that message in the original Form and then have the modal say Do you Agree or something?

So there are two questions here

1. Is it possible to use this code after someone has already clicked submit (onsubmit) or will it submit both a cancel and an agree?

2. If not, Is it possible to embed that large message, or document somehow into the widget instead of under the message: section of the modal?

 

mattmm
Kilo Sage

So I ended up doing this a little differently for anyone who finds their way here.  I decided to create a catalog item that had one Field after the Confidentiality Agreement. Within that field I had two values, Agree or Cancel.

If someone chose Agree and Submit it submitted as normal and created a Request and Requested Item that went off on a  Approval workflow.

If they chose Cancel it would have an alert message saying "You have chosen to Cancel this agreement. No Acceptance or Approval request will be submitted."

 

I did this by creating an OnSubmit Catalog Client Script on my Catalog Item with the following code:

 function onSubmit() {

{
var disagree = g_form.getValue('insert_your_variable_value_here'); //Get the value from the select box

	if (disagree == 'Cancel') { //If Disagree is selected from the select box.

{

alert("You have chosen to Cancel this agreement. No Acceptance or Approval request will be submitted.");

return false;
}
}
return true; 
}
}

Sebastian Piech
Tera Contributor
spModal.open({
            message: 'By clicking the Agree button below you confirm you have read, understood , and agree with the Confidentiality Agreement',
            title: 'Confidentiality Agreement',
            buttons: [{ label: '✘ Cancel', cancel: true},
                { label: '✔ Agree', primary: true }
            ]
        })
        .then(function(confirm) {
            g_form.submit(); //not sure if this will work - they say save() could work, but not in my case
        }, function() {
            alert('advising the person had cancelled this and it returns to the homepage');
            var url = '/home';
            top.window.location = url;
        }
        );