2013-01-19 38 views
1

我使用simple_form寶石,我需要從輸入變「created_at」字段的類型text_field(爲了使用jQuery的日期選擇器這個領域)。可能嗎?簡單的形式。如何覆蓋輸入爲text_field?

as: :string 

是不適合的回答,因爲它不與jQuery.datepicker

工作
+0

顯示你的代碼。 – Substantial

+0

它基那的diplicate:HTTP://stackoverflow.com/questions/5007785/how-do-i-write-a-cleaner-date-picker-input-for-simpleform –

+0

謝謝,rik.vanmechelen。這是我需要的 –

回答

0

據需要創建在app /輸入特定DatePickerInput類/ date_picker.rb

app/inputs/date_picker.rb 

class DatePickerInput < SimpleForm::Inputs::StringInput 
    def input      
    value = object.send(attribute_name) if object.respond_to? attribute_name 
    input_html_options[:value] ||= I18n.localize(value) if value.present? 
    input_html_classes << "datepicker" 

    super # leave StringInput do the real rendering 
    end 
end 

的javascript

jQuery -> 
$('input.date_picker').datepicker() 

形式只需添加以下行

= f.input :due, as: :date_picker 

這個線程解決我的問題How do i write a cleaner date picker input for SimpleForm感謝里奧