Question

I use the validate plugin on a form to get the correct input.

When that is done I also need to do a confirm if an input value is more then 50% larger than last input (that is stored in hidden field in form). I think of a dialog saying "is it ok that new number if 50% plus? yes/no". No, then they go back to the firm, yes then it fires.

I have tried around with some custom functions but same problem is that the validate plugin for jQuery keeps submitting the form so my confirm dialog pops up over and over and over.

So question is: How can I add a confirm after the validate plugin is done and ready to fire the form? Or other solution to same problem.

BR. Anders

  • Last solution is to do it serverside but that is not so smooth
Was it helpful?

Solution

You could use the submitHandler callback:

$('#myform').validate({
    submitHandler: function(form) {
        if (confirm('blabla?')) {
            form.submit();
        }
    }
});

Quote from the doc:

Callback for handling the actual submit when the form is valid. Gets the form as the only argument. Replaces the default submit. The right place to submit a form via Ajax after it validated. Use submitHandler to process something and then using the default submit. Note that "form" refers to a DOM element, this way the validation isn't triggered again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top