You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Jason Wang <ja...@bulletin.net> on 2009/04/24 05:50:55 UTC

Whats the best way to do a form component validation?

Hi all,

I have a form with a couple form components, most of which have 
validators attached. For example, the mobile number input field has a 
patternValidator attached:

mobile.add(new PatternValidator("^[1-9]([0-9]{8,14})"));

I have hooked all the validation actions with "onblur" events using this:

AjaxFormValidatingBehavior.addToAllFormComponents(signUpForm, "onblur", 
Duration.ONE_SECOND);

But unfortunately all the validations are triggered as soon as the focus 
leaves any of the form component.

Is there a way to hook the validator(like the patterValidator) with the 
event(onblur for example) on the form component(the mobile filed) rather 
than the whole form?

It would be nice that the AjaxFormValidatingBehavior class could provide 
the option to trigger the validations on events on every components.

Thanks.

Jasonw



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Whats the best way to do a form component validation?

Posted by Liam Clarke-Hutchinson <li...@steelsky.co.nz>.
That's the one.

On 4/24/09, Jason Wang <ja...@bulletin.net> wrote:
> Liam Clarke-Hutchinson wrote:
>> I use an AjaxFormComponentSubmittingBehavior onblur for each field -
>> so it triggers the submission processing behaviour (including
>> validation) for the given field - although it updates the model. You
>> could use an applicable Ajax behaviour and then call the component's
>> validate() method if you wanted to avoid the model update.
>>
>> Regards,
>>
>> Liam Clarke
>>
>> On Fri, Apr 24, 2009 at 3:50 PM, Jason Wang <ja...@bulletin.net>
>> wrote:
>>
>>> Hi all,
>>>
>>> I have a form with a couple form components, most of which have
>>> validators
>>> attached. For example, the mobile number input field has a
>>> patternValidator
>>> attached:
>>>
>>> mobile.add(new PatternValidator("^[1-9]([0-9]{8,14})"));
>>>
>>> I have hooked all the validation actions with "onblur" events using this:
>>>
>>> AjaxFormValidatingBehavior.addToAllFormComponents(signUpForm, "onblur",
>>> Duration.ONE_SECOND);
>>>
>>> But unfortunately all the validations are triggered as soon as the focus
>>> leaves any of the form component.
>>>
>>> Is there a way to hook the validator(like the patterValidator) with the
>>> event(onblur for example) on the form component(the mobile filed) rather
>>> than the whole form?
>>>
>>> It would be nice that the AjaxFormValidatingBehavior class could provide
>>> the
>>> option to trigger the validations on events on every components.
>>>
>>> Thanks.
>>>
>>> Jasonw
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
> Thanks for the reply. I think you meant
> "AjaxFormComponentUpdatingBehavior
> <http://wicket.apache.org/docs/1.4/org/apache/wicket/ajax/form/AjaxFormComponentUpdatingBehavior.html>".
>
> I will give it a try. Any other options to discuss?
>
> Regards,
> Jasonw
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Whats the best way to do a form component validation?

Posted by Jason Wang <ja...@bulletin.net>.
Liam Clarke-Hutchinson wrote:
> I use an AjaxFormComponentSubmittingBehavior onblur for each field -
> so it triggers the submission processing behaviour (including
> validation) for the given field - although it updates the model. You
> could use an applicable Ajax behaviour and then call the component's
> validate() method if you wanted to avoid the model update.
>
> Regards,
>
> Liam Clarke
>
> On Fri, Apr 24, 2009 at 3:50 PM, Jason Wang <ja...@bulletin.net> wrote:
>   
>> Hi all,
>>
>> I have a form with a couple form components, most of which have validators
>> attached. For example, the mobile number input field has a patternValidator
>> attached:
>>
>> mobile.add(new PatternValidator("^[1-9]([0-9]{8,14})"));
>>
>> I have hooked all the validation actions with "onblur" events using this:
>>
>> AjaxFormValidatingBehavior.addToAllFormComponents(signUpForm, "onblur",
>> Duration.ONE_SECOND);
>>
>> But unfortunately all the validations are triggered as soon as the focus
>> leaves any of the form component.
>>
>> Is there a way to hook the validator(like the patterValidator) with the
>> event(onblur for example) on the form component(the mobile filed) rather
>> than the whole form?
>>
>> It would be nice that the AjaxFormValidatingBehavior class could provide the
>> option to trigger the validations on events on every components.
>>
>> Thanks.
>>
>> Jasonw
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>   
Thanks for the reply. I think you meant 
"AjaxFormComponentUpdatingBehavior 
<http://wicket.apache.org/docs/1.4/org/apache/wicket/ajax/form/AjaxFormComponentUpdatingBehavior.html>".

I will give it a try. Any other options to discuss?

Regards,
Jasonw

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Whats the best way to do a form component validation?

Posted by Liam Clarke-Hutchinson <li...@steelsky.co.nz>.
I use an AjaxFormComponentSubmittingBehavior onblur for each field -
so it triggers the submission processing behaviour (including
validation) for the given field - although it updates the model. You
could use an applicable Ajax behaviour and then call the component's
validate() method if you wanted to avoid the model update.

Regards,

Liam Clarke

On Fri, Apr 24, 2009 at 3:50 PM, Jason Wang <ja...@bulletin.net> wrote:
> Hi all,
>
> I have a form with a couple form components, most of which have validators
> attached. For example, the mobile number input field has a patternValidator
> attached:
>
> mobile.add(new PatternValidator("^[1-9]([0-9]{8,14})"));
>
> I have hooked all the validation actions with "onblur" events using this:
>
> AjaxFormValidatingBehavior.addToAllFormComponents(signUpForm, "onblur",
> Duration.ONE_SECOND);
>
> But unfortunately all the validations are triggered as soon as the focus
> leaves any of the form component.
>
> Is there a way to hook the validator(like the patterValidator) with the
> event(onblur for example) on the form component(the mobile filed) rather
> than the whole form?
>
> It would be nice that the AjaxFormValidatingBehavior class could provide the
> option to trigger the validations on events on every components.
>
> Thanks.
>
> Jasonw
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org