Validates_presence_of on alternative fields

Hello!

I am trying to validate presence of one of two form fields.
I want to check if there is only one from two possible checkbox
selected.
I tried to find any hints in documentation, but as a beginner I wasn’t
able to invent solution.

Best regards!
Piotr

Why don’t you use a radiobox?

Regards,

TSU. Amador Cuenca

On 15 February 2011 12:39, Piotroslav [email protected] wrote:

Hello!

I am trying to validate presence of one of two form fields.
I want to check if there is only one from two possible checkbox
selected.
I tried to find any hints in documentation, but as a beginner I wasn’t
able to invent solution.

Validation is not on form fields but on data about to be saved to the
database. Do you have two columns in the table, one for each
checkbox? If so, and only one of them should be selected then reduce
it to a single column. As far as the form is concerned you may be
better with a radio box as Amador has suggested. If you need them to
be checkboxes you could use javascript to clear one when the other is
selected.

Colin

Well I am using Hobo, which in my case generates form with boolean
fields as checkbox.
Form is rendered from following dryml:

Validation I want to use would be placed in Lead model for specified transition, but if we could do it other way it would be fine too.

To be honest I am not sure how to put javascript inside it (but its
true it would be much easier with js) nor how to switch to radioboxes.
If you know what should I do please give me a hint.

I’ll ask similar question on Hobo group.

Best regards,
Piotr