You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "Emmanouil Batsis (Manos)" <ma...@abiss.gr> on 2012/04/01 04:18:01 UTC

HOWTO to only skip "required" validators

I have a usecase for saving a draft of a form before actually submitting it.

I'm trying to figure out how to only skip the "required" validators 
using a "save draft" submit button in my form. Disabling default form 
processing sounds like using a bazooka to shoot down a fly considering 
my form has a dynamic number of fields etc.

My only thought so far is to keep a reference of mandatory fields and 
call their setRequired with false within the submit button's onSubmit.

Would that work? Is there a better way?

Cheers,

Maons

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


Re: HOWTO to only skip "required" validators

Posted by Stijn Maller <st...@gmail.com>.
I'm a bit late in responding so I don't know if this is still useful to
you, but here is how we solved your requirement in our project. I'd still
like to find a more elegant approach, but it is the least intrusive
approach I could come up with and it sure beats the bazooka one. (which
could really spiral out of control depending on the complexity of your
application)

Step 1: create a marker interface
public interface ISkipRequiredCheck { }

Step 2: mark the buttons that need to skip the required checks
private class SaveButton extends Button implements ISkipRequiredCheck {
// Your button code
}

Step 3: do not set the fields required, but override isRequired
@Override
public boolean isRequired() {
return !this.getForm().findSubmittingButton() instanceof ISkipRequiredCheck;
}

Re: HOWTO to only skip "required" validators

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

On Sun, Apr 1, 2012 at 4:18 AM, Emmanouil Batsis (Manos) <ma...@abiss.gr> wrote:
>
> I have a usecase for saving a draft of a form before actually submitting it.
>
> I'm trying to figure out how to only skip the "required" validators using a
> "save draft" submit button in my form. Disabling default form processing
> sounds like using a bazooka to shoot down a fly considering my form has a
> dynamic number of fields etc.
>
> My only thought so far is to keep a reference of mandatory fields and call
> their setRequired with false within the submit button's onSubmit.
>
> Would that work? Is there a better way?

Wont work. onSubmit() is called later than the validators.

Use the bazooka instead :-)
Set button's default processing to false, then in onSubmit visit all
form components and call convertInput() + updateModel() for each,
finally save them.

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



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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


Re: HOWTO to only skip "required" validators

Posted by Jeff Schneller <je...@mootus.com>.
Don't mark the fields as required and check the fields during the submit of the save and throw appropriate error message. The save as draft would not check the fields. It is not the most elegant solution but it works and is easy to implement. 


On Mar 31, 2012, at 10:18 PM, "Emmanouil Batsis (Manos)" <ma...@abiss.gr> wrote:

> 
> I have a usecase for saving a draft of a form before actually submitting it.
> 
> I'm trying to figure out how to only skip the "required" validators using a "save draft" submit button in my form. Disabling default form processing sounds like using a bazooka to shoot down a fly considering my form has a dynamic number of fields etc.
> 
> My only thought so far is to keep a reference of mandatory fields and call their setRequired with false within the submit button's onSubmit.
> 
> Would that work? Is there a better way?
> 
> Cheers,
> 
> Maons
> 
> ---------------------------------------------------------------------
> 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