Skip to main content
Nintex Community Menu Bar

Prevent form submission from javascript

  • May 23, 2016
  • 3 replies
  • 19 views

Forum|alt.badge.img+6

Hello,

Is there a way to prevent form submission based on javascript validations?

e.g. i would like to use the following code:

NWF$(document).submit(function () {

alert('Custom validations!');

return false;

});

Instead of 'return false', I would assume there is a 'NWF.FormFiller.Functions.[?]' function to abort/prevent the form submission?

3 replies

Forum|alt.badge.img+6
  • Author
  • May 23, 2016

After playing around with it I found the following jQuery workaround which worked for me:

event.preventDefault();

If anyone knows a better solution, please share it with the rest of us happy.png


Forum|alt.badge.img+11
  • Nintex Partner
  • May 23, 2016

Hi Themos,

nice workaround. I've done this before by writing my validate function in js (e.g. validateOnSubmit()) and then configured my submit buttons "Client click" option with:

return validateOnSubmit()

Only if the function returns true, the form will be submitted. This may be a more "standard" version but not necessarily a "better" one.

Regards

Philipp


Forum|alt.badge.img+6
  • Author
  • May 23, 2016

Hey Philipp,

Nice solution, I hadn't thought of that!

Still, the ideal scenario would be to not even have to attach anything to specific buttons...

i.e. add the validation to the .submit() function, and prevent the submission from there!

Unfortunately, any code appended from javascript is executed AFTER the form gets posted back sad.png

so we have to attach the function to the specific button... Unless we can change the order of attached functions?!