【问题标题】:Display the value of a range slider with activeadmin and formtastic使用 activeadmin 和 formtastic 显示范围滑块的值
【发布时间】:2012-02-16 13:07:27
【问题描述】:
我正在使用带有范围字段的 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
我的滑块显示良好,但我没有看到滑块的值。当我们移动滑块时,我想在 :hint 上看到它的值。
我该怎么做?
【问题讨论】:
标签:
ruby-on-rails
ruby-on-rails-3
formtastic
activeadmin
【解决方案1】:
我需要同样的东西——这就是我最终解决它的方法(仅在 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
【解决方案2】:
f.input :discount_percent, :as => :range, :in => 0..100, :step => 0.5
咖啡脚本文件:
$ ->
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)})")
所以我改变了标签的值,看起来一点也不差