grimen / validatious-on-rails

Rails plugin that maps model validations to class names on form elements to integrate with Validatious. IMPORTANT: Project is not maintained anymore.
MIT License
346 stars 13 forks source link

problem validating input element of type radio #23

Open resistorsoftware opened 14 years ago

resistorsoftware commented 14 years ago

Problem seems to from my setup as follows: Post belongs_to :category. I use HAML for templates.

class Post < ActiveRecord::Base belongs_to :category validates_presence_of :category

So now, in Formtastic I am displaying some radio buttons for category via the Formtastic setup:

which generates the radio buttons. Pressing submit however does not validate that a radio was selected, and by default none is selected.

The generated HTML is:

<legend><span class="label">Category<abbr title="required">*</abbr></span>    </legend><ol><li><label for="post_category_id_1"><input id="post_category_id_1" name="post[category_id]" value="1" type="radio"> Cat 1</label></li><li><label for="post_category_id_2"><input id="post_category_id_2" name="post[category_id]" value="2" type="radio"> Cat 2</label></li><li><label for="post_category_id_3"><input id="post_category_id_3" name="post[category_id]" value="3" type="radio">Cat 3</label></li></ol>

So I am stuck here. I see no class of "presence" added to my radio's. That seems to be the problem, but I am not sure why.

If I change to validation_presence_of :category_id

to ensure a category radio button is picked, a Javascript error is thrown about an illegal character... but the radios are rendered with the "presence" class.

How to get radio's generated like this to validate?

grimen commented 14 years ago

WIll review this when I get time, feel free to help me out by creating a app/spec that re-produce this behaviour.

grimen commented 14 years ago

resistorsoftware said:

Hi,

For sure there is a problem... using the belongs_to association causes an error in the way the javascript tries to hook in to the validation. I am sure it is simply off by an _id or something.

I will look into helping you for sure...

bwlang commented 14 years ago

i'm seeing a similar problem here... maybe it's a result of formtastic wrapping labels around the radio input elements (instead of putting them after like validatious examples show) - just a guess