-
Notifications
You must be signed in to change notification settings - Fork 84
Using with simple form
Gabriel Sobrinho edited this page Nov 11, 2015
·
1 revision
If you want to make all of your date/datetime inputs to use a text field and i18n with simple form, you can implement a custom input like this:
# app/inputs/date_time_input.rb
class DateTimeInput < SimpleForm::Inputs::Base
enable :placeholder
def input(wrapper_options = nil)
merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
@builder.text_field(attribute_name, merged_input_options)
end
def input_html_options
input_html_options = super
input_html_options[:value] = I18n.l(attribute_value) if attribute_value
input_html_options
end
protected
def attribute_value
@value ||= object.send(attribute_name)
end
end