From c2c7d95c5632c94ba0400192784476bc6f1757a6 Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Thu, 16 May 2013 21:39:14 +0300 Subject: [PATCH] add html5 component support to input_field closes #802 --- CHANGELOG.md | 5 +++++ lib/simple_form/form_builder.rb | 6 ++++-- test/form_builder/input_field_test.rb | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index baeef67c..fdcd38b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## master + +### enhancements + * `input_field` supports `html5` component [@nashby](https://github.com/nashby) + ## 3.0.0.rc ### enhancements diff --git a/lib/simple_form/form_builder.rb b/lib/simple_form/form_builder.rb index 2bac0665..7680c6e5 100644 --- a/lib/simple_form/form_builder.rb +++ b/lib/simple_form/form_builder.rb @@ -12,6 +12,8 @@ module SimpleForm update: :edit } + ATTRIBUTE_COMPONENTS = [:html5, :min_max, :maxlength, :placeholder, :pattern, :readonly] + extend MapType include SimpleForm::Inputs @@ -135,10 +137,10 @@ module SimpleForm # def input_field(attribute_name, options={}) options = options.dup - options[:input_html] = options.except(:as, :collection, :label_method, :value_method) + options[:input_html] = options.except(:as, :collection, :label_method, :value_method, *ATTRIBUTE_COMPONENTS) options = @defaults.deep_dup.deep_merge(options) if @defaults - SimpleForm::Wrappers::Root.new([:min_max, :maxlength, :placeholder, :pattern, :readonly, :input], wrapper: false).render find_input(attribute_name, options) + SimpleForm::Wrappers::Root.new(ATTRIBUTE_COMPONENTS + [:input], wrapper: false).render find_input(attribute_name, options) end # Helper for dealing with association selects/radios, generating the diff --git a/test/form_builder/input_field_test.rb b/test/form_builder/input_field_test.rb index 3c969803..755ad85b 100644 --- a/test/form_builder/input_field_test.rb +++ b/test/form_builder/input_field_test.rb @@ -21,6 +21,23 @@ class InputFieldTest < ActionView::TestCase assert_select 'textarea#user_name.text' end + test 'builder input_field should generate input type based on column type' do + with_concat_form_for(@user) do |f| + f.input_field :age + end + + assert_select 'input[type=number].integer#user_age' + end + + test 'builder input_field should be able to disable any component' do + with_concat_form_for(@user) do |f| + f.input_field :age, html5: false + end + + assert_no_select 'input[html5=false]#user_age' + assert_select 'input[type=text].integer#user_age' + end + test 'builder input_field should allow passing options to input tag' do with_concat_form_for(@user) do |f| f.input_field :name, id: 'name_input', class: 'name'