问题
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