Dan Diephouse wrote:
Kevin Menard wrote:


On Sep 20, 2005, at 3:06 PM, Dan Diephouse wrote:

Is there an easy way to make validation conditional? For instance I have a set of radio options. If the user chooses option1, I'd like the fields under option 1 to be validated. If they choose option 2, I'd like the fields under option 2 to be validated and so on.

I looked a bit at the Required validator class, but I couldn't figure out how to check if another field was set to another value.



I was trying to figure out how to do something similar a little while back. I tried a bunch of different things before I arrived at my current solution. What I do is have something like the following for a component definition in a page spec:

<binding name="validators" value="fieldRequired"/>

Then, in the page class I have something like:

@Bean
    public abstract Required getRequired();


public Validator getFieldRequired()
    {
        if (true == someCondition)
        {
            return getRequired();
        }

        return null;
    }

I haven't tried this with a list of validators, but I suppose it would work just as well.


Well thats clever. Works great for me. Thanks!

- Dan


Actually I have one issue. I'd like to impose a maxLength on some of the fields. I can't seem to figure out how to mix regular ol' validators and my validator which is a field:

<binding name="validators" value="validators: maxLength=2, fieldRequired"/>

That was the best I can come up with... I know you can use a $ to reference a bean, but this is a property on my page. How would I reference that?

- Dan




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to