You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by fatefree <fa...@gmail.com> on 2008/10/21 15:28:13 UTC

Ajax validating individual form fields

I have been trying to fulfill a requirement of a form, where each field is
validated one at a time after losing focus, and the entire form is validated
when a user clicks submit. I can see that there are pieces of what I want to
do thats possible, but I haven't been able to put them all together.

What I have tried is using the
AjaxFormValidatingBehavior.addToAllFormComponents(form, "onblur"), but as
you probably know this causes the entire form to be validated on the onblur
which is both confusing to a user who hasnt been able to put all values in,
and also seems to be excessive load as id rather the rest of the form be
ignored.

Then I looked into nested forms with the hope that I could add the same
behavior to a nested form, and then a user could submit a parent form which
would submit its child forms. While i thought this could be a solution, it
seems that when an inner form is submitted through the onblur behavior
above, the parent form is submitted and validated as well so I have the same
problem as I do in the first case. Keep in mind I have no button to submit
an individual field (so i cant call setdefaultformprocessing).

So finally I thought about making every field its own form without being
nested, in which case I know the validating behavior will work for every
form individually. The only problem (besides having a form for every input,
but thats manageable) is that I don't know how to use a button outside of
these forms, and force it to submit every form and proceed only if they are
all valid. I tried using an AjaxLink and calling process on every form i
have a reference to, but that seems to return true every time without any
validation.

Has anyone had a similar requirement or accomplished what I am trying to do?
I would be very appreciative of any example or ideas or direction i should
look into to accomplish this. Thanks in advance
-- 
View this message in context: http://www.nabble.com/Ajax-validating-individual-form-fields-tp20090299p20090299.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: Ajax validating individual form fields

Posted by fatefree <fa...@gmail.com>.
Just a little update, I managed to get the form level validator working by
doing what you said, basically creating a validator that takes a component
as an argument, and compares the ivalidatable.value against the model
object:

                 protected void onValidate(IValidatable validatable) {
	
if(!validatable.getValue().toString().equals(component.getModelObjectAsString()))
			error(validatable);
	}

Unfortunately the getResetPassword is a final method for some reason, so I
was not able to override it as I hoped. Instead I did this on the ajaxbutton
used to submit the form: 

	                         protected void onAfterRender() {
				super.onAfterRender();
				pass.setResetPassword(false);
			}
			
			protected void onBeforeRender() {
				super.onBeforeRender();
				pass.setResetPassword(true);
			}

And that seemed to work for the password fields. Thanks for your help!
-- 
View this message in context: http://www.nabble.com/Ajax-validating-individual-form-fields-tp20090299p20118595.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: Ajax validating individual form fields

Posted by Daan van Etten <da...@stuq.nl>.
Hi fatefree,

On 22 okt 2008, at 03:53, fatefree wrote:

> Thank you very much, I didn't realize that the
> AjaxFormComponentUpdatingBehavior submitted individual components, I  
> guess i
> got it confused with AjaxFormValidatingBehavior.
>
> I think the only issue is when a form level validator needs to be  
> used, for
> instance to compare that two fields are equal. Am I correct in  
> assuming
> theres no way to attach a form component validator to a field and  
> have it
> compare against the value of another component? If so I'm not sure  
> if it
> would be possible to fire a form level validator on the onblur of  
> the second
> component without submitting the entire form.
I think you are correct.
Maybe it is an option to write a custom validator that compares the  
two fields, and attach that to the second field. The error can then be  
shown at the second field.

> Another issue I thought of is if you use a password text field you  
> wouldn't
> be able to use AjaxFormComponentUpdatingBehavior because even if the  
> input
> is valid it would erase immediately. Maybe there is a clever way to  
> override
> the isPasswordReset so that it only is true when the form is submit  
> through
> a button and not that behavior?

I have no idea, but am curious to see your solution :-).

Regards,

Daan

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


Re: Ajax validating individual form fields

Posted by fatefree <fa...@gmail.com>.
Thank you very much, I didn't realize that the
AjaxFormComponentUpdatingBehavior submitted individual components, I guess i
got it confused with AjaxFormValidatingBehavior. 

I think the only issue is when a form level validator needs to be used, for
instance to compare that two fields are equal. Am I correct in assuming
theres no way to attach a form component validator to a field and have it
compare against the value of another component? If so I'm not sure if it
would be possible to fire a form level validator on the onblur of the second
component without submitting the entire form.

Another issue I thought of is if you use a password text field you wouldn't
be able to use AjaxFormComponentUpdatingBehavior because even if the input
is valid it would erase immediately. Maybe there is a clever way to override
the isPasswordReset so that it only is true when the form is submit through
a button and not that behavior?



Daan (StuQ) wrote:
> 
> Hi fatefree,
> 
> Check this blog post:
> http://stuq.nl/weblog/2008-09-03/user-friendly-form-validation-with-wicket
> I think this achieves what you want.
> 
> Regards,
> 
> Daan
> 
> 

-- 
View this message in context: http://www.nabble.com/Ajax-validating-individual-form-fields-tp20090299p20102724.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: Ajax validating individual form fields

Posted by Daan van Etten <da...@stuq.nl>.
Hi fatefree,

Check this blog post: http://stuq.nl/weblog/2008-09-03/user-friendly-form-validation-with-wicket
I think this achieves what you want.

Regards,

Daan

On 21 okt 2008, at 15:28, fatefree wrote:

>
> I have been trying to fulfill a requirement of a form, where each  
> field is
> validated one at a time after losing focus, and the entire form is  
> validated
> when a user clicks submit. I can see that there are pieces of what I  
> want to
> do thats possible, but I haven't been able to put them all together.
>
> What I have tried is using the
> AjaxFormValidatingBehavior.addToAllFormComponents(form, "onblur"),  
> but as
> you probably know this causes the entire form to be validated on the  
> onblur
> which is both confusing to a user who hasnt been able to put all  
> values in,
> and also seems to be excessive load as id rather the rest of the  
> form be
> ignored.
>
> Then I looked into nested forms with the hope that I could add the  
> same
> behavior to a nested form, and then a user could submit a parent  
> form which
> would submit its child forms. While i thought this could be a  
> solution, it
> seems that when an inner form is submitted through the onblur behavior
> above, the parent form is submitted and validated as well so I have  
> the same
> problem as I do in the first case. Keep in mind I have no button to  
> submit
> an individual field (so i cant call setdefaultformprocessing).
>
> So finally I thought about making every field its own form without  
> being
> nested, in which case I know the validating behavior will work for  
> every
> form individually. The only problem (besides having a form for every  
> input,
> but thats manageable) is that I don't know how to use a button  
> outside of
> these forms, and force it to submit every form and proceed only if  
> they are
> all valid. I tried using an AjaxLink and calling process on every  
> form i
> have a reference to, but that seems to return true every time  
> without any
> validation.
>
> Has anyone had a similar requirement or accomplished what I am  
> trying to do?
> I would be very appreciative of any example or ideas or direction i  
> should
> look into to accomplish this. Thanks in advance
> -- 
> View this message in context: http://www.nabble.com/Ajax-validating-individual-form-fields-tp20090299p20090299.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> 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