You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Thomas Götz <to...@decoded.de> on 2012/03/14 21:53:03 UTC

Check if FormComponent is valid in later request

Hi!

I have the following situation:

I have a form containing several FormComponents and Validators, submitted via Ajax. Then I have an AjaxButton on the same page (outside the form) which triggers some backend logic. But it should only do so if the mentioned form had no validation errors during the last submit. How should I check that? Form.hasError() only checks for error messages, which always returns 'false' as the error messages already have been rendered in one of the preceding requests.

Is it a good idea to set a flag in the Form (boolean isValid) upon onSubmit/onError and check for that flag or is there some already provided Wicket mechanic I could use?

Cheers,
   -Tom


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


Re: Check if FormComponent is valid in later request

Posted by Thomas Götz <to...@richmountain.de>.
Exactly! My bad I mentioned AjaxButton. It should read 'AjaxFormComponentUpdatingBehavior' on a DropDownChoice, was trying to generalize the problem for explaining, but 'AjaxButton' was a bad example …

Wouldn't it be convenient if a Form (or FormComponent) whould remembered their 'valid' state so you could check for it in later (e.g. Ajax) requests?

   -Tom


Dan Retzlaff wrote:

> If I understand Thomas correctly, the button is not a form submitting
> button. It's outside the form and is handled on a request after the form is
> submitted.
> 
> Thomas, I think if you want to avoid resubmitting the form then you'll need
> to set your own "formSubmittedSuccessfully" state in Form#onSubmit. Form
> doesn't remember what happened on previous requests; it either updates
> models on success or creates error messages on failure.
> 
> On Wed, Mar 14, 2012 at 2:00 PM, Igor Vaynberg <ig...@gmail.com>wrote:
> 
>> if the form is invalid your button's onsubmit() wont get fired...
>> 
>> -igor
>> 
>> On Wed, Mar 14, 2012 at 1:53 PM, Thomas Götz <to...@decoded.de> wrote:
>>> Hi!
>>> 
>>> I have the following situation:
>>> 
>>> I have a form containing several FormComponents and Validators,
>> submitted via Ajax. Then I have an AjaxButton on the same page (outside the
>> form) which triggers some backend logic. But it should only do so if the
>> mentioned form had no validation errors during the last submit. How should
>> I check that? Form.hasError() only checks for error messages, which always
>> returns 'false' as the error messages already have been rendered in one of
>> the preceding requests.
>>> 
>>> Is it a good idea to set a flag in the Form (boolean isValid) upon
>> onSubmit/onError and check for that flag or is there some already provided
>> Wicket mechanic I could use?
>>> 
>>> Cheers,
>>>  -Tom
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> 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
>> 
>> 


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


Re: Check if FormComponent is valid in later request

Posted by Dan Retzlaff <dr...@gmail.com>.
If I understand Thomas correctly, the button is not a form submitting
button. It's outside the form and is handled on a request after the form is
submitted.

Thomas, I think if you want to avoid resubmitting the form then you'll need
to set your own "formSubmittedSuccessfully" state in Form#onSubmit. Form
doesn't remember what happened on previous requests; it either updates
models on success or creates error messages on failure.

On Wed, Mar 14, 2012 at 2:00 PM, Igor Vaynberg <ig...@gmail.com>wrote:

> if the form is invalid your button's onsubmit() wont get fired...
>
> -igor
>
> On Wed, Mar 14, 2012 at 1:53 PM, Thomas Götz <to...@decoded.de> wrote:
> > Hi!
> >
> > I have the following situation:
> >
> > I have a form containing several FormComponents and Validators,
> submitted via Ajax. Then I have an AjaxButton on the same page (outside the
> form) which triggers some backend logic. But it should only do so if the
> mentioned form had no validation errors during the last submit. How should
> I check that? Form.hasError() only checks for error messages, which always
> returns 'false' as the error messages already have been rendered in one of
> the preceding requests.
> >
> > Is it a good idea to set a flag in the Form (boolean isValid) upon
> onSubmit/onError and check for that flag or is there some already provided
> Wicket mechanic I could use?
> >
> > Cheers,
> >   -Tom
> >
> >
> > ---------------------------------------------------------------------
> > 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: Check if FormComponent is valid in later request

Posted by Igor Vaynberg <ig...@gmail.com>.
if the form is invalid your button's onsubmit() wont get fired...

-igor

On Wed, Mar 14, 2012 at 1:53 PM, Thomas Götz <to...@decoded.de> wrote:
> Hi!
>
> I have the following situation:
>
> I have a form containing several FormComponents and Validators, submitted via Ajax. Then I have an AjaxButton on the same page (outside the form) which triggers some backend logic. But it should only do so if the mentioned form had no validation errors during the last submit. How should I check that? Form.hasError() only checks for error messages, which always returns 'false' as the error messages already have been rendered in one of the preceding requests.
>
> Is it a good idea to set a flag in the Form (boolean isValid) upon onSubmit/onError and check for that flag or is there some already provided Wicket mechanic I could use?
>
> Cheers,
>   -Tom
>
>
> ---------------------------------------------------------------------
> 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