Skip to content

Commit

Permalink
Merge pull request heartcombo#803 from plataformatec/issue-802
Browse files Browse the repository at this point in the history
add html5 component support to input_field
  • Loading branch information
nashby committed May 20, 2013
2 parents 1ad1f9f + c2c7d95 commit 1da255e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## master

### enhancements
* `input_field` supports `html5` component [@nashby](https://github.com/nashby)

## 3.0.0.rc

### enhancements
Expand Down
6 changes: 4 additions & 2 deletions lib/simple_form/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class FormBuilder < ActionView::Helpers::FormBuilder
update: :edit
}

ATTRIBUTE_COMPONENTS = [:html5, :min_max, :maxlength, :placeholder, :pattern, :readonly]

extend MapType
include SimpleForm::Inputs

Expand Down Expand Up @@ -135,10 +137,10 @@ def input(attribute_name, options={}, &block)
#
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
Expand Down
17 changes: 17 additions & 0 deletions test/form_builder/input_field_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 1da255e

Please sign in to comment.