I'm trying to have a dynamically updated min value on one field, depending on input from other fields. Heres my code in short:
$("#new_project").live("click", function() {
switch($('input:radio[name=quality-level]:checked').val()){
case 'average' : ppw = .006;
case 'below-average' : ppw =.004;
case 'good' : ppw = .008;
case 'very-good' : ppw = .016;
}
if ($('#minimum-word-length').val() && $('input:radio[name=quality-level]:checked').val())
{
min_price = $('#minimum-word-length').val() * ppw;
}
$("#new_project, .edit_project").validate({
rules: {
...
"price-per-article": {required: true, number: true, min:min_price},
...
},
errorPlacement: function(error, element) { }
});
});
Min price is set correctly, and updates correctly. That said, for whatever reason, the min value rule doesnt update which i think is because the validate code is only loaded on document load. So I guess is there a way to reload the rules so that the min value changes when then the two necessary fields are filled?
Thanks!
The problem is you're setting up the validate object with the price-per-article on initial load. I'm not familiar with the validate plug-in, but in general, if your properties change for an object real time, you'll want to use a callback function for that property as opposed to setting it's data on load.
So for the price-per-article entry it'd probably look like:
"price-per-article": {
required: true,
number: true,
min: function () { return $('#minimum-word-length').val() * ppw; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With