我有一個自定義文本輸入,我試圖顯示一個默認值。該值被設置在HTML中,但不顯示在實際輸入中。Rails simple_form默認輸入值不顯示
我的自定義輸入:
<%= f.input :expired_at, as: :date_time_picker %>
我自己也嘗試沒有運氣:
class DateTimePickerInput < SimpleForm::Inputs::Base
def input(wrapper_options)
template.content_tag(:div, class: "input-group", style: "width: 100%;") do
template.concat @builder.text_field(attribute_name, input_html_options)
template.concat span_icon
end
end
def input_html_options
super.merge({ class: 'text datetimepicker form-control', "data-date-input": "", value: default_value })
end
def span_icon
template.content_tag(:span, class: "input-group-addon") do
template.content_tag(:i, class: "material-icons") do
"date_range"
end
end
end
def default_value
object.send(attribute_name).to_time.strftime("%F %I:%M %p") if object.send(attribute_name).present?
end
end
我打電話的輸入方式
<%= f.input :expired_at, as: :date_time_picker, input_html: { value: evaluation.expired_at } %>
我也嘗試用一個簡單的字符串"hello"
替換default_value
方法來測試它呈現。它不是。
「值上的HTML設置,但在實際輸入不顯示」。不確定你的意思 - 你能發佈生成的html嗎? –