vendredi 28 novembre 2014

JQuery Validation


I have a select "ArrearsLHOLocation" that has an option "None Selected" with a value of -1 and all other selectable values are greater than 0.


Here is the rule defined in my javascript



$("#ArrearsLHOLocation").rules("add", {
min: {
depends: function (elem) {
return $("#rbArrearsLHO[value='True']").is(":checked") ? 0 : -1;
}
},
messages: {
min: "You have stated that the applicant/coapplicant have LHO arrears but you have not stated where!"
}
});


Here are the watches as observed in Chrome.



$("#rbArrearsLHO[value='True']").is(":checked") ? 0 : -1: 0
$("#rbArrearsLHO[value='True']").is(":checked"): true
$("#ArrearsLHOLocation").val(): "-1"
$("#ArrearsLHOLocation").val() >=($("#rbArrearsLHO[value='True']").is(":checked") ? 0 : -1): false


This page successfully submits, incorrectly. If I toggle the radio button and the watches appear like this:



$("#rbArrearsLHO[value='True']").is(":checked") ? 0 : -1: -1
$("#rbArrearsLHO[value='True']").is(":checked"): false
$("#ArrearsLHOLocation").val(): "-1"
$("#ArrearsLHOLocation").val() >=($("#rbArrearsLHO[value='True']").is(":checked") ? 0 : -1): true


This page is stopped from being submitted and my error message is displayed.


What am I doing wrong?


Steve





Aucun commentaire:

Enregistrer un commentaire