You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by gorny <dh...@gmail.com> on 2013/03/18 12:12:49 UTC

group of requred fields

Hi,
I have a form with two required fields for example: "age" and "dateOfBirth",
all of them are required, but if they are in special group, then only one of
them is required.
In my custom class CustomFieldBlocks.java which  implements
PropertyOverrides, I should return field validator for the field. 
The main question is: How to implement custom validator with only one
required field from set of fields. 
For example : 
private FieldValidator getValidator(Field field) {
        FieldValidator contextValidator = context.getValidator(field);
        PropertyModel propertyModel =
beanModel.getById(context.getPropertyId());
        String propertyLabel = propertyModel.getPropertyName();
        if (propertyModel != null &&
mandatoryCustomFields.contains(propertyLabel)) {
                 List<Field> fields = new ArrayList<Field>();
//                 here I want to get all required fields for pass
                 for (String fieldLabel : mandatoryCustomFields){
                      Field field = ?????
                      fields.add(field);
                 }
                GroupValidator groupValidator = new GroupValidator(fields,
"groupValidator");
                return new
CompositeFieldValidator(Arrays.asList(groupValidator, contextValidator));
        } else {
                FieldValidator required =
fieldValidatorSource.createValidator(field, "required", null);
                return new CompositeFieldValidator(Arrays.asList(required,
contextValidator));
       }
       return contextValidator;
    }



--
View this message in context: http://tapestry.1045711.n5.nabble.com/group-of-requred-fields-tp5720512.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: group of requred fields

Posted by Lance Java <la...@googlemail.com>.
Here's an example
http://jumpstart.doublenegative.com.au/jumpstart/examples/input/morevalidation



--
View this message in context: http://tapestry.1045711.n5.nabble.com/group-of-requred-fields-tp5720512p5720518.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: group of requred fields

Posted by Lance Java <la...@googlemail.com>.
Yes, and if your read the javadoc for FieldValidator it says "Responsible for
validation of a single field."
http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/FieldValidator.html

Since you need to validate a group of fields, you will need to use the
form's validate event. eg onValidateFromMyForm() where MyForm is the id of
your form.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/group-of-requred-fields-tp5720512p5720517.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: group of requred fields

Posted by gorny <dh...@gmail.com>.
I have groups of fields with only one required field in the same group (any
but only one field from such group must be specified) It is all i need in
the BeanEditor where amount of fields vary on some conditions.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/group-of-requred-fields-tp5720512p5720516.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: group of requred fields

Posted by Lance Java <la...@googlemail.com>.
FieldValidators are only for when you want to validate a single field at a
time. If you want to validate a group of fields, use the onValidateFromX()
function where X is your form id.

http://jumpstart.doublenegative.com.au/jumpstart/examples/input/mixedvalidation
http://tapestry.apache.org/forms-and-validation.html



--
View this message in context: http://tapestry.1045711.n5.nabble.com/group-of-requred-fields-tp5720512p5720513.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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