add html5 component support to input_field

closes #802
This commit is contained in:
Vasiliy Ermolovich 2013-05-16 21:39:14 +03:00
parent 1ad1f9f895
commit c2c7d95c56
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'