diff --git a/lib/active_admin_datetimepicker/base.rb b/lib/active_admin_datetimepicker/base.rb index b8bd45b..84ca03f 100644 --- a/lib/active_admin_datetimepicker/base.rb +++ b/lib/active_admin_datetimepicker/base.rb @@ -18,20 +18,25 @@ def input_html_options(input_name = nil, placeholder = nil) options[:class] = [self.options[:class], html_class].compact.join(' ') options[:data] ||= input_html_data options[:data].merge!(datepicker_options: datetime_picker_options) - options[:value] = input_value(input_name) + options[:value] = input_value(input_name, options) options[:maxlength] = 19 options[:placeholder] = placeholder unless placeholder.nil? end end def input_value(input_name = nil) + return options[:value] if options[:value].present? + val = object.public_send(input_name || method) - if val.nil? - val - elsif column.type == :date + + return nil if val.nil? + + if column.type == :date val - else + elsif column.type == :datetime DateTime.new(val.year, val.month, val.day, val.hour, val.min, val.sec).strftime(format) + else + val.to_s end end diff --git a/spec/filters_and_edit_form_spec.rb b/spec/filters_and_edit_form_spec.rb index ef12838..fc5d8ff 100644 --- a/spec/filters_and_edit_form_spec.rb +++ b/spec/filters_and_edit_form_spec.rb @@ -81,6 +81,7 @@ date_birthday = Date.today.beginning_of_month.strftime("%Y-%m-%d") expect(page.find('#author_birthday').value).to start_with(date_birthday) expect(page).to have_css('#author_birthday[placeholder="Formtastic placeholder"]') + expect(page).to have_css('#author_birthday[value="Formtastic value"]') end end diff --git a/spec/support/admin.rb b/spec/support/admin.rb index 6850abe..5ef1ba5 100644 --- a/spec/support/admin.rb +++ b/spec/support/admin.rb @@ -11,7 +11,7 @@ def add_author_resource(options = {}, &block) f.inputs 'General' do f.input :name - f.input :birthday, as: :date_time_picker, input_html: { placeholder: 'Formtastic placeholder' } + f.input :birthday, as: :date_time_picker, input_html: { placeholder: 'Formtastic placeholder', value: 'Formtastic Value' } end f.actions