我正在使用带有范围字段的activeadmin:
ActiveAdmin.register Card do
form :html => { :enctype => "multipart/form-data" } do |f|
f.inputs "Traitements" do
f.input :treatment_chlore, :as => :range, :in => 0..10, :step => 0.5
end
f.buttons
end
end
我有滑块显示但我看不到滑块的值。当我们移动滑块时,我希望在:提示上看到它的值。
我该怎么做?
答案 0 :(得分:3)
我需要同样的东西 - 这就是我最终解决它的方法(仅在Chrome上测试.YMMV)
(我对这里的内联javascript处理程序并不感到高兴。如果有人有更好的解决方案与active_admin一起使用,请发表评论。)
ActiveAdmin.register Card do
form :html => { :enctype => "multipart/form-data" } do |f|
f.inputs "Traitements" do
f.input :treatment_chlore, {
:as => :range,
:in => 0..10,
:step => 0.5,
:html_input => {:oninput => "card_treatment_chlore_output.value = this.valueAsNumber",
:hint => %Q{value: <output for="card_treatment_chlore" name="card_treatment_chlore_output">#{resource.treatment_chlore}</output> }.html_safe
}
end
f.buttons
end
end
答案 1 :(得分:0)
f.input :discount_percent, :as => :range, :in => 0..100, :step => 0.5
coffeescript文件:
$ ->
text = $("label[for='frequency_discount_percent']").text()
$("label[for='frequency_discount_percent']").text("#{text} (#{parseFloat($("#frequency_discount_percent").val()).toFixed(1)})")
$("#frequency_discount_percent").change ->
$("label[for='frequency_discount_percent']").text("#{text} (#{parseFloat(this.value).toFixed(1)})")
所以我改变了标签的价值,看起来一点也不差