[jQuery] Re: Validate: calling validate() from within a function

2008-11-20 Thread Jörn Zaefferer
You could bind a submit event handler before calling validate. That
way your handler should be executed before the validation.

$(#myform).submit(myHandler).validate();

Jörn

On Thu, Nov 20, 2008 at 10:02 AM, Arpan Dhandhania [EMAIL PROTECTED] wrote:

 Hi,
I am using jQuery's validate plugin. I followed the examples and
 have defined $(#signup-form).validate(...) inside $(document).ready
 (...). This works for me.

 What this does is that when I submit the form, it calls validate().
 What I want to do is call validate() from within a function. When the
 form is submited, I want to call a function which in turn calls
 validate (after processing some of the fields).

 I was wondering if this is supported, or if there is a work around for
 this problem.

 thanks in advance,
 Arpan D



[jQuery] Re: Validate: calling validate() from within a function

2008-11-20 Thread Arpan Dhandhania

Thanks Jorn. But if 'myHandler' returned false? What I want is that if
'myHandler' returns false, it should not go ahead with the validate().
I am handling that case separately. If 'myHandler' returned true, it
should proceed.

Arpan D

On Nov 20, 5:09 pm, Jörn Zaefferer [EMAIL PROTECTED]
wrote:
 You could bind a submit event handler before calling validate. That
 way your handler should be executed before the validation.

 $(#myform).submit(myHandler).validate();

 Jörn


[jQuery] Re: Validate: calling validate() from within a function

2008-11-20 Thread Jörn Zaefferer
Did you just try that?

Jörn

On Thu, Nov 20, 2008 at 2:14 PM, Arpan Dhandhania [EMAIL PROTECTED] wrote:

 Thanks Jorn. But if 'myHandler' returned false? What I want is that if
 'myHandler' returns false, it should not go ahead with the validate().
 I am handling that case separately. If 'myHandler' returned true, it
 should proceed.

 Arpan D

 On Nov 20, 5:09 pm, Jörn Zaefferer [EMAIL PROTECTED]
 wrote:
 You could bind a submit event handler before calling validate. That
 way your handler should be executed before the validation.

 $(#myform).submit(myHandler).validate();

 Jörn


[jQuery] Re: Validate: calling validate() from within a function

2008-11-20 Thread Arpan Dhandhania

Ya, it worked, but even if I return false in the myHandler function,
validation is still going happening.

Arpan D

On Nov 20, 7:11 pm, Jörn Zaefferer [EMAIL PROTECTED]
wrote:
 Did you just try that?

 Jörn

 On Thu, Nov 20, 2008 at 2:14 PM, Arpan Dhandhania [EMAIL PROTECTED] wrote:

  Thanks Jorn. But if 'myHandler' returned false? What I want is that if
  'myHandler' returns false, it should not go ahead with the validate().
  I am handling that case separately. If 'myHandler' returned true, it
  should proceed.

  Arpan D

  On Nov 20, 5:09 pm, Jörn Zaefferer [EMAIL PROTECTED]
  wrote:
  You could bind a submit event handler before calling validate. That
  way your handler should be executed before the validation.

  $(#myform).submit(myHandler).validate();

  Jörn


[jQuery] Re: Validate: calling validate() from within a function

2008-11-20 Thread Jörn Zaefferer
I think that is an issue of how jQuery handles events. It calls each
handler for on element/event, not stopping when one handler returns
false, but only afterwards.

You could work around that by disabling all event handling and calling
validate manually:

$(#form).myHandle(function() {
  // whatever
  if (ok) {
$(this).valid();
  }
}).validate({
  onsubmit: false,
  // maybe also these
  onkeyup: false,
  onfocusout: false
});

Jörn

On Thu, Nov 20, 2008 at 3:45 PM, Arpan Dhandhania [EMAIL PROTECTED] wrote:

 Ya, it worked, but even if I return false in the myHandler function,
 validation is still going happening.

 Arpan D

 On Nov 20, 7:11 pm, Jörn Zaefferer [EMAIL PROTECTED]
 wrote:
 Did you just try that?

 Jörn

 On Thu, Nov 20, 2008 at 2:14 PM, Arpan Dhandhania [EMAIL PROTECTED] wrote:

  Thanks Jorn. But if 'myHandler' returned false? What I want is that if
  'myHandler' returns false, it should not go ahead with the validate().
  I am handling that case separately. If 'myHandler' returned true, it
  should proceed.

  Arpan D

  On Nov 20, 5:09 pm, Jörn Zaefferer [EMAIL PROTECTED]
  wrote:
  You could bind a submit event handler before calling validate. That
  way your handler should be executed before the validation.

  $(#myform).submit(myHandler).validate();

  Jörn