Ruby on rails 简单表单:单选按钮/复选框使用字段集/图例
从可访问性的角度来看,为单选按钮和复选框使用Ruby on rails 简单表单:单选按钮/复选框使用字段集/图例,ruby-on-rails,accessibility,simple-form,Ruby On Rails,Accessibility,Simple Form,从可访问性的角度来看,为单选按钮和复选框使用fieldset/legend组合非常重要: fieldset legend What is your sex? label for="male" Male input type="radio" id="male" label for="female" Female input type="radio" id="female" 即使在字段集/legend对中,也会出现这种情况,如下所示: fieldset legend P
fieldset/legend
组合非常重要:
fieldset
legend What is your sex?
label for="male" Male
input type="radio" id="male"
label for="female" Female
input type="radio" id="female"
即使在字段集/legend
对中,也会出现这种情况,如下所示:
fieldset
legend Personal information
label for="name"
input type="text" id="name"
fieldset // Yes, this is a fieldset inside a fieldset!
legend What is your sex?
label for="male" Male
input type="radio" id="male"
label for="female" Female
input type="radio" id="female"
label for="email"
input type="text" id="email"
不过,Simple_Form会自动为这些图例生成标签元素。有没有一种简单的方法告诉Simple_Form创建fieldset/legend
s,或者我必须使用自定义包装来解决这个问题
更新
作为第一个解决方案,我创建了一个自定义包装器,如下所示:
config.wrappers :vertical_radio_and_checkboxes, tag: 'fieldset', class: 'form-group', error_class: 'has-error' do |b|
b.use :html5
b.optional :readonly
b.wrapper tag: 'legend', class: 'col-sm-3 control-label' do |ba|
ba.use :label # TODO: Doesn't need to be a label tag, see http://stackoverflow.com/questions/29261556/simple-form-use-fieldset-legend-for-radio-buttons-checkboxes
end
b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
ba.use :input
ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
end
end
这暂时还可以,尽管我没有找到一种方法告诉Simple_Form不要为标签生成标签
元素(它不指向任何ID,这意味着它无论如何都不能是正确的用法,但它添加了一些重要的CSS类,所以我不想放弃它而使用标签文本
)
我已经在Simple\u Form-Bootstrap回购中添加了一个问题:。为了防止生成Simple\u Form
您可以使用:label=>false
例如,在您的表单.haml
中:
= f.input :name, :label => false
以你的形式
这就是你想要实现的吗?不确定这就是你问题的全部原因
以防万一,可能会有一些有用的信息不,不是。所有内容都应该像以前一样输出,但是不应该为radiobutton/复选框组的名称使用额外的标签
标记,而是应该有一个图例
输出。所有内容都应该由字段集
包围。