The value of the second password field should equal to the value of the first password field before the action method may be invoked.

validating id-77

Suppose, we have a model called The problem here is that accepts_nested_attributes_for call destroy for child objects AFTER validation of the parent object. Of course, later, when the user will try to edit a company, he/she will get an error - “Company should have at least one office.”.

), and it actually works, but again, it does not take into account the fact that some of the records may be marked for destruction. To sort out the problem, we need to understand what Hopefully, in Rails 3 we are now able to write our own custom validators, so I’ve added one more for this case.

If you know a better solution, don’t hesitate to contact me or simply leave a comment below.

the one have to be lesser than the other), validating correctness of the three separate day, month and year fields, etcetera.

The cleanest solution would be to create a custom component which renders two or more components and use a specific validator for that, but that would involve more work.

The easiest solution in this particular case is to attach the validator to the first component of the group (components are rendered, validated, converted and updated in the same order as you define them in the JSF view) and pass the other component(s) as unique .

This example demonstrates a basic registration form with one username field and two password fields.

There is no standard way to attach one validator to multiple fields.

They will by default validate only one field at once.

Although there are some situations where you want this kind of functionality.

For example validating the password confirmation field, validating the range of two numeric or date values (e.g.