【问题标题】:Rails / radio button with images in labels and options disabledRails / 单选按钮,标签和选项中的图像已禁用
【发布时间】:2014-10-20 21:29:27
【问题描述】:

Rails 4. 我正在尝试创建一个单选按钮

1) 带有文字加图片的标签

2) 可以(或不)禁用选项

我可以解决 1) 与 f.collection_radio_buttons 和 2) 与 f.input...但我找不到解决 2 点的解决方案...

有只使用简单表单助手的解决方案吗? (不带 js/Jquery)

感谢您的帮助。

【问题讨论】:

    标签: ruby-on-rails-4 radio-button simple-form


    【解决方案1】:

    我会试着回答自己:

    这段代码解决了2点:

     <%= f.collection_radio_buttons( :typepayment, 
                                     [[0,t(:radio_button_type_payment_None)], [1,t(:radio_button_type_payment_DirectDebit)], [2,t(:radio_button_type_payment_CreditCard)]],
                                     :first,
                                     :last,
                                     item_wrapper_tag: :div
                                   ) do |b|
                                       b.label {  (condition_is_disabled ? b.radio_button(disabled: "\"disabled\"") : b.radio_button) + " "+
                                                 (b.value == 0 ? t(:radio_button_type_payment_None) : (b.value == 1 ? t(:radio_button_type_payment_DirectDebit) : t(:radio_button_type_payment_CreditCard) )) +
                                                 (b.value != 0 ? image_tag("typepayment_#{b.value}.png", class: "img_type_payment") : "") }
                                     end
    
     %>
    

    collection_radio_buttons的块代码是在这里用图像构建labee的。

    disabled: "\"disabled\"" :我没有找到其他方法将disabled 状态传递给助手

    如果有人有更好的答案,欢迎:)

    【讨论】:

      猜你喜欢
      • 2014-08-26
      • 2021-01-20
      • 1970-01-01
      • 2012-12-12
      • 2016-05-21
      • 2020-06-24
      • 2012-10-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多