Hello all

I have added a method on jQuery validator like this

    $.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() {
        }
    });

the form looks like this

<div id="wrapper_form">
    <form id="educationForm" name="educationForm" method="post"
action="">
    <table width="500" border="0">
      <tr>
        <td width="100">Period:</td>
        <td width="200"><input type="text" name="txt_begin"
id="txt_begin" size="8" maxlength="4" class="required year ui-widget-
content ui-corner-all" /> to
        <input type="text" name="txt_end" id="txt_end" size="8"
maxlength="4" class="required year ui-widget-content ui-corner-all" /
></td>
        <td width="200"></td>
      </tr>
      <tr>
        <td colspan="2">
        <input type="submit" name="btn_submit" id="btn_submit"
value="Submit" class="ui-button ui-state-default ui-corner-all" />
        <input type="button" name="btn_cancel" id="btn_cancel"
value="Cancel" class="ui-button ui-state-default ui-corner-all" />
        </td>
        <td> </td>
      </tr>
    </table>
    </form>
</div>

but why the custom method I added didn't work?

return value == element.value; // this one here didn't work :(

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 "<=" ) I have tested this method with
greater or equal and lower or equal by replacing the "==" with ">=" or
with "<=" It didn't work either

Reply via email to