Note that there are some explanatory texts on larger screens.

plurals
  1. POdetecting submit button in jQuery validation's submitHandler
    primarykey
    data
    text
    <p>I have a form that requires some post validation warnings. The concept is simply, the values are allowed, but out of normal range. The way this is being handled is in the validation submitHandler:</p> <pre><code>$('form').validate({ highlight: function (element, errorClass) {$(element).addClass("invalidElem");}, unhighlight: function (element, errorClass) {$(element).removeClass("invalidElem");}, errorPlacement: function (error, element) {element.parent().parent().next().children().last().append(error);}, errorClass: "errorMsg", submitHandler: function (form) { if (!WeightsRangeValidator("Height", txtHeight, heightWarning)) { return false; } if (!WeightsRangeValidator("Weight", txtWeight, weightWarning)) { return false; } form.submit(); } }); </code></pre> <p>The problem is that there is both a submit and a cancel button on the form. The cancel button does have the class 'cancel' so that the validation does not execute. The submitHandler function is being called still, though. I assume there has to be a way to detect which of the submit buttons is being clicked as to bypass the contents of the submitHandler handler.</p> <hr> <p>here is a working jsFiddler: <a href="http://jsfiddle.net/scarleton/ZSVFP/" rel="nofollow">http://jsfiddle.net/scarleton/ZSVFP/</a></p> <p>There are three valid states of the form: either check box (but not both) or both text boxes and the drop down. The validation works when you click on OK. The problem comes in on the cancel. If you enter anything into the text box and press cancel, the validation still tries to validate. I tried added the following handler and it allows cancel if the form is valid, but not if letters are entered in the text box.</p> <pre><code>btnCancel.click(function () { txtHeight.rules("remove"); txtWeight.rules("remove"); ddlDevice.rules("remove"); $("#form").submit(); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload