gpt4 book ai didi

ruby-on-rails - Ruby on Rails 标签函数。为什么radio_button_tag.id 的大小写与label.for 不匹配?

转载 作者:数据小太阳 更新时间:2023-10-29 08:05:49 26 4
gpt4 key购买 nike

在注册 openstreetmap 时,在条款页面上,我注意到单击标签并没有选中与其关联的单选按钮。这是 html:

<!-- legale is GB --> 
<form action="/user/terms" method="post">
<p>
Please select your country of residence:

<input id="legale_fr" name="legale"
onchange="Element.update(&quot;contributorTerms&quot;, &quot;&lt;img alt=\&quot;Searching\&quot; src=\&quot;/images/searching.gif?1313181320\&quot; /&gt;&quot;);; new Ajax.Request('/user/terms?legale=FR', {asynchronous:true, evalScripts:true})"
type="radio" value="FR" />
<label for="legale_FR">France</label>

<input id="legale_it" name="legale" ... type="radio" value="IT" />
<label for="legale_IT">Italy</label>

<input checked="checked"
id="legale_gb" name="legale" ... type="radio" value="GB" />
<label for="legale_GB">Rest of the world</label>
</p>
</form>

如您所见,复选框 id="legale_gb" 与标签 for="legale_GB" 不匹配。

现在 openstreetmap 的网站实际上是开源的,所以我们可以阅读 terms.html.erb :

<!-- legale is <%= @legale %> -->
<% form_tag :action => 'terms' do %>
<p>
<%= t 'user.terms.legale_select' %>
<% [['france', 'FR'], ['italy', 'IT'], ['rest_of_world', 'GB']].each do |name,legale| %>
<%=
radio_button_tag 'legale', legale, @legale == legale,
:onchange => remote_function(
:before => update_page do |page|
page.replace_html 'contributorTerms', image_tag('searching.gif')
end,
:url => {:legale => legale}
)
%>
<%= label_tag "legale_#{legale}", t('user.terms.legale_names.' + name) %>
<% end %>
</p>
<% end %>

我是 Rails 新手,但我看不到任何将单选按钮标签的 id 小写的内容。更重要的是,即使我查看 radio_button_tag 的来源, sanitize_to_id我看不出这是从哪里来的。

有人知道是什么原因造成的吗?

编辑 根据

的回答,将我的描述中的 label 换成 radio

最佳答案

2 件事:

  1. 错误的标签,违规者是 radio_button_tag(它在标签中按预期设置了上限)。

  2. 您似乎链接到了错误的 Rails。根据这个项目的environment.rb ,它使用的是 Rails 2.3.14。如果你看radio_button_tag对于该版本,您会看到罪魁祸首。

    # our pretty tag value is downcased on line 318
    pretty_tag_value = value.to_s.gsub(/\s/, "_").gsub(/(?!-)\W/, "").downcase

    # although the pretty name is not, oddly
    pretty_name = name.to_s.gsub(/\[/, "_").gsub(/\]/, "")

    # then the two are combined into the HTML id
    html_options = { ..., "id" => "#{pretty_name}_#{pretty_tag_value}", ... }

关于ruby-on-rails - Ruby on Rails 标签函数。为什么radio_button_tag.id 的大小写与label.for 不匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7576174/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com