> Thats helpful, but my problem is that I don't know the field id either, so I 
> can't inject the field.  The fields are determined at run time (attributes
> that the user can add or remove) so it has to be flexible.

I'm going to assume that you are not dynamically generating your .tml
files and that you have a <t:textfield..> in a <t:loop> rendering your
attributes. In that case you have only one field, and can know the id.

> I supposed I could put every TextField in an IF statement where the IF has 
> "required" and the ELSE doesn't, but that seems like I'm missing a better way 
> to do it.
If you can wrap the TextField in an If, then surely you can use a
getDynamicConstraints() type solution and switch the return value
based on whatever you'd put in the if.

public FieldValidator getDynamicConstraints() {
        if (currentAttributeIsRequired()) {
            constraint = "required";
        }
        return source.createValidators(valueField, constraint);
    }


Josh

On Tue, May 24, 2011 at 11:47 AM,  <jackkuros...@w9z.org> wrote:
> Thats helpful, but my problem is that I don't know the field id either, so I 
> can't inject the field.  The fields are determined at run time (attributes 
> that the user can add or remove) so it has to be flexible.
>
> I supposed I could put every TextField in an IF statement where the IF has 
> "required" and the ELSE doesn't, but that seems like I'm missing a better way 
> to do it.
>
> Jack
>
> -----Original Message-----
> From: "Thiago H. de Paula Figueiredo" <thiag...@gmail.com>
>
> @Inject FieldValidatorSource and use its FieldValidator
> createValidators(Field field, String specification) method to generate a
> FieldValidator. Then create a FieldValidator getValidator() method using
> createValidators() and add t:validate="prop:validator" to your TextField.
>
> Example (taken from
> http://tapestry.1045711.n5.nabble.com/Validation-based-on-condition-td2435565.html):
>
> @Inject
> private FieldValidatorSource source;
>
> @InjectComponent
> private Field yourField;
>
> public FieldValidator getDynamicConstraints() {
>        return source.createValidators(yourField, "required", null);
> }
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to