Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery validation custom method didn't work
    text
    copied!<p>I have added a method on jQuery validator like this</p> <pre><code> $.validator.addMethod( 'myEqual', function (value, element) { return value == element.value; // this one here didn't work }, 'Please enter a greater year!' ); $.metadata.setType("attr", "validate"); $("#educationForm").validate({ showErrors: function(errorMap, errorList) { this.defaultShowErrors(); }, errorPlacement: function(error, element) { error.appendTo( element.parent("td").next("td") ); }, /*success: function(label) { label.text("ok!").addClass("success"); },*/ rules: { txt_end: { required: true, myEqual: "#txt_begin" } }, submitHandler: function() {} }); </code></pre> <p>the form looks like this</p> <pre><code>&lt;div id="wrapper_form"&gt; &lt;form id="educationForm" name="educationForm" method="post" action=""&gt; &lt;table width="500" border="0"&gt; &lt;tr&gt; &lt;td width="100"&gt;Period:&lt;/td&gt; &lt;td width="200"&gt;&lt;input type="text" name="txt_begin" id="txt_begin" size="8" maxlength="4" class="required year ui-widget-content ui-corner-all" /&gt;&amp;nbsp;to&amp;nbsp; &lt;input type="text" name="txt_end" id="txt_end" size="8" maxlength="4" class="required year ui-widget-content ui-corner-all" /&gt;&lt;/td&gt; &lt;td width="200"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="2"&gt; &lt;input type="submit" name="btn_submit" id="btn_submit" value="Submit" class="ui-button ui-state-default ui-corner-all" /&gt; &lt;input type="button" name="btn_cancel" id="btn_cancel" value="Cancel" class="ui-button ui-state-default ui-corner-all" /&gt; &lt;/td&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p>but why the custom method I added didn't work?</p> <pre><code>return value == element.value; // this one here didn't work </code></pre> <p>it always return true for any value am I missing something here? I didn't use the built in method because later in the form I would require to write another method to check for greater or equal and lower or equal ( ">=" and "&lt;=" ) I have tested this method with greater or equal and lower or equal by replacing the "==" with ">=" or with "&lt;=" It didn't work either</p>
 

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