Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/active_admin_datetimepicker/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions spec/filters_and_edit_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion spec/support/admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down