cancel
Showing results for 
Search instead for 
Did you mean: 
Crack_Jack
Nintex Newbie

Not able to stop save button saving the form using custom OnClick function

Jump to solution

Hi 

I want to put some custom validation and seems like I doesn't work like it suppose to. I have used the same command for on-prem and this worked fine. When I click the button and  function value is false ,it will stuck at saving the form and neither does it save or come back to ask for filling the missing data. Any idea how we can go back to initial screen for filling the missing data if the value is false.

 

CustomSave.png

Saving.PNG

Labels: (1)
0 Kudos
Reply
7 Replies
MegaJerk
Nintex Newbie

Re: Not able to stop save button saving the form using custom OnClick function

Jump to solution

It's probably because when you click the button it starts the 'Submit' event, which will always be handled and will try to Submit the Form. 

Ideally, you should not be doing validation using something that isn't a Validation Rule. If the configuration of your Form is Invalid, then it would be wise to simply Invalidate the Control(s) that do not pass the check. Additionally, you use this in parallel with Formatting Rules to prevent access to certain controls based off of the selections made elsewhere. 

If you'd like to add a custom function to your Save and Submit button that ensures that the Validity of the Form is confirmed before it's submitted, you can use the following code: 

(function(event) {
      var myAlert = confirm("Do you really wanna process this form!?");
      
      if (!myAlert || (!Page_ClientValidate() && NWF$(".nf-validation-summary").hide().length > 0)) {        
        /* Validation FAILED */

        /* This will force the Form to scroll to the top */
        NWF$("#s4-workspace").scrollTop(0);

        /* This will prevent the Form from firing the Submit event */
        event.preventDefault();
      } else {
        /* Validation PASSED */

        /* Optional place for housekeeping if you'd like to
        perform some type of work before the Form is
        committed to SharePoint */

        /* 
          NWF$("#" + someControl).prop("checked", true); 
        */
      }
    }(event));


This should ensure that the Form is Valid before it's submitted, and if it isn't, will scroll to the top of the Form in order to show the user that there are Validation Issues (which will be shown in the Validation Summary). 

On the other hand if it is valid, then nothing of importance will happen unless you so choose to place code inside of the 'else{}' block. 

0 Kudos
Reply
Crack_Jack
Nintex Newbie

Re: Not able to stop save button saving the form using custom OnClick function

Jump to solution

Thanks, after giving some thoughts I did it with rules. Will try this method when I face some limitations over there.

0 Kudos
Reply
Jack2019
Nintex Newbie

Re: Not able to stop save button saving the form using custom OnClick function

Jump to solution

Have same issue, where to place the code? Custom JavaScript in form setting?

 

0 Kudos
Reply
MegaJerk
Nintex Newbie

Re: Not able to stop save button saving the form using custom OnClick function

Jump to solution

image.png

 

You place it in the Settings of a Button: 

image.png

0 Kudos
Reply
Jack2019
Nintex Newbie

Re: Not able to stop save button saving the form using custom OnClick function

Jump to solution

Thanks, MegaJerk. It does not working, it shows message "Do you really wanna process this form!?" but not stop Submit. In my submit button, it has a redirect() to redirect it to Thanks page, is that affect? see picturesubmitcodeIn.jpg

0 Kudos
Reply
Jack2019
Nintex Newbie

Re: Not able to stop save button saving the form using custom OnClick function

Jump to solution

I use a few validation rules such as 

and(equals(PanelSelect,"Panel 1"),isNullOrEmpty({Self}))

within several panels. the validation rules for required fields within panels are working ( if not be filled, the form would not be submitted), but Submit button would not stop the submission since the Client Click is set redirecting to Submission page (Redirect()). How can it stop, like a required field set in Sharepoint List' column?

Tags (1)
0 Kudos
Reply
MegaJerk
Nintex Newbie

Re: Not able to stop save button saving the form using custom OnClick function

Jump to solution

Being that this thread has already been marked as solved, and it is a thread that you did not start with the explicit purposes of asking these questions, I advise you to please create a NEW thread so that a conversation can take place there without bothering the original creator of this one. 

Thank You. 

0 Kudos
Reply