[jQuery] Re: Resetting validation rules dynamically

2008-06-20 Thread kapowaz

I see one thing I've done wrong above; the arguments to the method
provided to addMethod() should be (value, element) rather than just
(element). Unfortunately having changed this, it's still not working;
rather than getting a silent failure, the validation check is still
being applied to the element which shouldn't need it any more... Any
ideas?

Latest attempt: http://www.kapowaz.net/files/conditional-validation.html


[jQuery] Re: Resetting validation rules dynamically

2008-06-19 Thread Jörn Zaefferer

You need to make sure that your custom method checks for optional
elements. Check those additional methods for examples:
http://dev.jquery.com/view/trunk/plugins/validate/additional-methods.js

Jörn

On Wed, Jun 18, 2008 at 2:20 PM, kapowaz [EMAIL PROTECTED] wrote:

 Alright, I've found the bug with the above code (the callback function
 itself doesn't return true or false; only the anonymous method inside
 it does), and corrected it. However I've since stumbled upon another
 problem; if any field uses a callback method to determine required
 status, but *also* happens to use a custom validation method, it will
 always be flagged as required.

 I've augmented my demo at 
 http://www.kapowaz.net/files/conditional-validation.html
 to demonstrate this problem in action. Might this be a bug within the
 plugin itself, or am I doing something else wrong?



[jQuery] Re: Resetting validation rules dynamically

2008-06-19 Thread kapowaz

I'm trying to modify my custom method, as follows:

$.validator.addMethod('expiryDate', function(element){
var presentDate = new Date();
var selectedDateHash = parseInt($('#select-cardpayment-
expirymonth').val(), 10) + parseInt(($('#select-cardpayment-
expiryyear').val() * 12), 10);
var presentDateHash = (presentDate.getMonth()+1) +
(presentDate.getFullYear() * 12);
return this.optional(element) || selectedDateHash 
presentDateHash;
}, parseMessageText('errors.paymentForm.cardPayment.expiryDate'));

Unfortunately this doesn't work either; in fact, in Firefox the
validation silently fails to execute /at all/ once I call
this.optional(). I can't even reference it with the Firebug console
without it stopping JS execution. What gives? I wasn't even aware such
a method existed...?

On Jun 19, 4:22 pm, Jörn Zaefferer [EMAIL PROTECTED]
wrote:
 You need to make sure that your custom method checks for optional
 elements. Check those additional methods for 
 examples:http://dev.jquery.com/view/trunk/plugins/validate/additional-methods.js

 Jörn

 On Wed, Jun 18, 2008 at 2:20 PM, kapowaz [EMAIL PROTECTED] wrote:

  Alright, I've found the bug with the above code (the callback function
  itself doesn't return true or false; only the anonymous method inside
  it does), and corrected it. However I've since stumbled upon another
  problem; if any field uses a callback method to determine required
  status, but *also* happens to use a custom validation method, it will
  always be flagged as required.

  I've augmented my demo 
  athttp://www.kapowaz.net/files/conditional-validation.html
  to demonstrate this problem in action. Might this be a bug within the
  plugin itself, or am I doing something else wrong?


[jQuery] Re: Resetting validation rules dynamically

2008-06-18 Thread kapowaz

Alright, I've found the bug with the above code (the callback function
itself doesn't return true or false; only the anonymous method inside
it does), and corrected it. However I've since stumbled upon another
problem; if any field uses a callback method to determine required
status, but *also* happens to use a custom validation method, it will
always be flagged as required.

I've augmented my demo at 
http://www.kapowaz.net/files/conditional-validation.html
to demonstrate this problem in action. Might this be a bug within the
plugin itself, or am I doing something else wrong?