1
0
Fork 0
mirror of https://github.com/heartcombo/simple_form.git synced 2022-11-09 12:19:26 -05:00

Merge pull request #803 from plataformatec/issue-802

add html5 component support to input_field
This commit is contained in:
Vasiliy Ermolovich 2013-05-20 06:43:26 -07:00
commit 1da255ee39
3 changed files with 26 additions and 2 deletions

View file

@ -1,3 +1,8 @@
## master
### enhancements
* `input_field` supports `html5` component [@nashby](https://github.com/nashby)
## 3.0.0.rc
### enhancements

View file

@ -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

View file

@ -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'