使用activeadmin和formtastic显示范围滑块的值

我正在使用带有范围字段的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 

我有滑块显示良好,但我没有看到滑块的值。 当我们移动滑块时,我希望在:提示上看到它的值。

我怎样才能做到这一点?

我需要同样的东西 – 这就是我最终解决它的方法(仅在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: #{resource.treatment_chlore} }.html_safe } end f.buttons end end 
 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)})") 

所以我改变了标签的价值,看起来一点也不差

Interesting Posts