Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby on rails tag functions. Why does the case of radio_button_tag.id not match label.for?
    text
    copied!<p>While registering for openstreetmap, on the terms page, I noticed that clicking the labels didn't check the radio buttons associated with them. Here is the html:</p> <pre><code>&lt;!-- legale is GB --&gt; &lt;form action="/user/terms" method="post"&gt; &lt;p&gt; Please select your country of residence: &lt;input id="legale_fr" name="legale" onchange="Element.update(&amp;quot;contributorTerms&amp;quot;, &amp;quot;&amp;lt;img alt=\&amp;quot;Searching\&amp;quot; src=\&amp;quot;/images/searching.gif?1313181320\&amp;quot; /&amp;gt;&amp;quot;);; new Ajax.Request('/user/terms?legale=FR', {asynchronous:true, evalScripts:true})" type="radio" value="FR" /&gt; &lt;label for="legale_FR"&gt;France&lt;/label&gt; &lt;input id="legale_it" name="legale" ... type="radio" value="IT" /&gt; &lt;label for="legale_IT"&gt;Italy&lt;/label&gt; &lt;input checked="checked" id="legale_gb" name="legale" ... type="radio" value="GB" /&gt; &lt;label for="legale_GB"&gt;Rest of the world&lt;/label&gt; &lt;/p&gt; &lt;/form&gt; </code></pre> <p>As you can see the checkbox <code>id="legale_gb"</code> doesn't match the label <code>for="legale_GB"</code>.</p> <p>Now openstreetmap's website is actually open source so we can read the <a href="http://git.openstreetmap.org/rails.git/blob/HEAD:/app/views/user/terms.html.erb#l9" rel="nofollow">terms.html.erb</a>:</p> <pre><code>&lt;!-- legale is &lt;%= @legale %&gt; --&gt; &lt;% form_tag :action =&gt; 'terms' do %&gt; &lt;p&gt; &lt;%= t 'user.terms.legale_select' %&gt; &lt;% [['france', 'FR'], ['italy', 'IT'], ['rest_of_world', 'GB']].each do |name,legale| %&gt; &lt;%= radio_button_tag 'legale', legale, @legale == legale, :onchange =&gt; remote_function( :before =&gt; update_page do |page| page.replace_html 'contributorTerms', image_tag('searching.gif') end, :url =&gt; {:legale =&gt; legale} ) %&gt; &lt;%= label_tag "legale_#{legale}", t('user.terms.legale_names.' + name) %&gt; &lt;% end %&gt; &lt;/p&gt; &lt;% end %&gt; </code></pre> <p>I'm a rails newbie, but I can't see anything there that lowercases the <code>id</code> of the radio button tag. What's more, even when I look at the source of <a href="http://github.com/rails/rails/blob/83d9398ec049e414ce5797b6bd00fda384705109/actionpack/lib/action_view/helpers/form_tag_helper.rb#L365" rel="nofollow">radio_button_tag</a>, <a href="http://github.com/rails/rails/blob/83d9398ec049e414ce5797b6bd00fda384705109/actionpack/lib/action_view/helpers/form_tag_helper.rb#L659" rel="nofollow">sanitize_to_id</a> I can't see where this is coming from.</p> <p>Anyone got any idea what's causing this?</p> <p><em>Edit</em> Swapped out <code>label</code> for <code>radio</code> in my description according to answer from </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload