【问题标题】:simple_form Collection Radio Buttonsimple_form 集合单选按钮
【发布时间】:2016-11-19 18:00:55
【问题描述】:

我有一个表单,其中这些单选按钮在两个表单之间重复:

= f.collection_radio_buttons :type, [['cardio', 'Cardio'], ['weights', 'Weights']], :first, :last, :item_wrapper_class => 'radio-inline'

有没有办法给单选按钮添加一个类,所以这些可以通过 jquery 轻松区分,你将如何使用 haml 来做到这一点,就好像我在 ID 上附加了一样,数据库上的值被改变了?

【问题讨论】:

  • 我从未使用过simple-form,但我认为它对你有用。加载页面时查看呈现的 html 并查看它输出的内容。当然,你可以不使用simple-form而使用the regular radio_button

标签: jquery ruby-on-rails haml simple-form


【解决方案1】:

一个集合单选按钮,例如:

form_for @user do |f|
  f.collection_radio_buttons :options, [[true, 'Yes'] ,[false, 'No']], :first, :last
end

结果

<input id="user_options_true" name="user[options]" type="radio" value="true" />
<label class="collection_radio_buttons" for="user_options_true">Yes</label>
<input id="user_options_false" name="user[options]" type="radio" value="false" />
<label class="collection_radio_buttons" for="user_options_false">No</label>

https://github.com/plataformatec/simple_form#collection-radio-buttons

因此,您应该尝试覆盖 CSS 类“collection_radio_buttons”和输入中生成的“ID”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-02
    • 2012-04-18
    • 1970-01-01
    • 2012-07-20
    相关资源
    最近更新 更多