Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem validating input element of type radio #23

Open
resistorsoftware opened this issue Nov 3, 2009 · 3 comments
Open

problem validating input element of type radio #23

resistorsoftware opened this issue Nov 3, 2009 · 3 comments

Comments

@resistorsoftware
Copy link

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:

  • semantic_form_for (@post, :html => {:class => 'validate'}) do |form|
    • form.inputs do
      = form.input :category, :as => :radio

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
Copy link
Owner

grimen commented Nov 4, 2009

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

@grimen
Copy link
Owner

grimen commented Nov 5, 2009

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
Copy link
Contributor

bwlang commented Nov 18, 2009

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants