Ruby on Rails Thursday, June 5, 2014

On Jun 5, 2014, at 8:49 AM, Ronald Fischer wrote:

> My form essentially looks like this:
>
> <%= form_for :xxx, url: xxxs_path, method: 'get', enforce_utf8:true do
> |d| %>
> <%= d.text_field('filter', value: @filter, maxlength:64, size:16) %>
> <%= d.radio_button(:filtertype, 'regexp') %>
> <%= d.label :filtertype_regexp, 'Regular Expression', value: 'regexp'
> %>
> <%= d.radio_button(:filtertype, 'lefteq', checked:true) %>
> <%= d.label :filtertype_lefteq, 'Starts with...', value: 'lefteq' %>
> <%= d.submit(value="FILTER LIST BELOW", name: 'filter') %>
> <% end %>
>
> I thought from this association between radio buttons and label,
> clicking on *text* (i.e. 'Regular Expression' should already cause the
> button to be selected, but this is not the case. Did I miss something
> here?

Look at the generated HTML in a browser. In order for the label to affect the radio button, one of two things must be true:

1. Either the label's "for" attribute exactly matches the radio button's "id" attribute, or
2. The label wraps around the button and does not have a "for" attribute.

Sometimes you have to get out and push a little with radio buttons, although looking at it briefly, you appear to be doing the right things by having the same name input into both the label and the radio.

Walter

>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/fb20194dc119e820ab3d7d624b52dbbb%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3268AFFF-9ED6-499F-9C92-8C92601546C7%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment