Display the value of a range slider with activeadmin and formtastic

喜夏-厌秋 提交于 2019-12-10 22:56:01

问题


I am using activeadmin with a range field :

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

I have the slider showing well but i don't see the value of the slider. When we move the slider, i want to see its value on a :hint.

How can i do that?


回答1:


I needed the same thing -- here's how I ended up solving it (only tested on Chrome. YMMV)

(I'm not crazy about the inline javascript handler here. If anyone has a better solution for use with active_admin, please comment.)

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

coffeescript file:

$ ->
  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)})")

So i have changed the value of label, seems not bad at all



来源:https://stackoverflow.com/questions/9311815/display-the-value-of-a-range-slider-with-activeadmin-and-formtastic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!