From e522459db1162b90d4665a8b6f5b00b5a3705428 Mon Sep 17 00:00:00 2001 From: Gena M Date: Thu, 20 Jun 2019 08:57:51 +0300 Subject: [PATCH] Add support of Formtastic::String input_html [refs #52] @mantoszew found the bug with range-input: - From/To placeholder are missing This commit aims to fix it. And also add support of other `input_html` options. For example: ```ruby form do |f| f.input :created_at, as: :date_time_picker, input_html: { placeholder: 'Text here...' } end ``` --- lib/active_admin_datetimepicker/base.rb | 15 ++++++++------- spec/filters_and_edit_form_spec.rb | 3 +++ spec/support/admin.rb | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/active_admin_datetimepicker/base.rb b/lib/active_admin_datetimepicker/base.rb index d31d811..f9365bf 100644 --- a/lib/active_admin_datetimepicker/base.rb +++ b/lib/active_admin_datetimepicker/base.rb @@ -14,13 +14,14 @@ def input_html_data end def input_html_options(input_name = nil, placeholder = nil) - options = {} - 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[:maxlength] = 19 - options + super().tap do |options| + 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[:maxlength] = 19 + options[:placeholder] = placeholder unless placeholder.nil? + end end def input_value(input_name = nil) diff --git a/spec/filters_and_edit_form_spec.rb b/spec/filters_and_edit_form_spec.rb index 7cd6b2a..1c0669e 100644 --- a/spec/filters_and_edit_form_spec.rb +++ b/spec/filters_and_edit_form_spec.rb @@ -38,6 +38,8 @@ expect(page.find('input#q_birthday_gteq').value).to start_with(date_from) expect(page.find('input#q_birthday_lteq').value).to start_with(date_to) + expect(page).to have_css('input#q_birthday_gteq[placeholder="From"]') + expect(page).to have_css('input#q_birthday_lteq[placeholder="To"]') end end @@ -59,6 +61,7 @@ it 'can set birthday' do 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"]') end end diff --git a/spec/support/admin.rb b/spec/support/admin.rb index ea143fc..022cd89 100644 --- a/spec/support/admin.rb +++ b/spec/support/admin.rb @@ -10,7 +10,7 @@ def add_author_resource(options = {}, &block) f.inputs 'General' do f.input :name - f.input :birthday, as: :date_time_picker + f.input :birthday, as: :date_time_picker, input_html: { placeholder: 'Formtastic placeholder' } end f.actions