Rails 4。我正在尝试创建一个单选按钮
1) 标签中带有文本和图像
2) 有选项可以(或不)禁用
我可以用f.collection_radio_buttons
求解1),用f.input
求解2)。。。但我找不到解决2点的方法。。。
是否有只使用简单表单助手的解决方案?(无js/Jquery)
谢谢你的帮助。
我会试着回答自己:
此代码解决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
的块代码是用来构造带有图像的标签的。
disabled: ""disabled""
:我没有找到其他方法将disabled
状态传递给助手
如果有人有更好的答案,欢迎:)