add components that don't generate tags for input_field

closes #632

Conflicts:

	lib/simple_form/form_builder.rb
This commit is contained in:
Vasiliy Ermolovich 2012-07-22 20:42:29 +03:00
parent e550556982
commit 88f6ae045e
3 changed files with 50 additions and 1 deletions

View File

@ -1,6 +1,10 @@
## 2.1.0.dev
### enhancements
* `input_field` supports components that don't generate tags
as `:min_max`, `:maxlength`, `:placeholder`, `:pattern`, `:readonly`.
Closes[#362](https://github.com/plataformatec/simple_form/issues/632).
([@nashby](https://github.com/nashby))
* support for Rails eager loading.
Closes [#478](https://github.com/plataformatec/simple_form/issues/478).
* generate required attribute for `date_time` input.

View File

@ -137,7 +137,7 @@ module SimpleForm
options[:input_html] = options.except(:as, :collection, :label_method, :value_method)
options = @defaults.deep_dup.deep_merge(options) if @defaults
SimpleForm::Wrappers::Root.new([:input], :wrapper => false).render find_input(attribute_name, options)
SimpleForm::Wrappers::Root.new([:min_max, :maxlength, :placeholder, :pattern, :readonly, :input], :wrapper => false).render find_input(attribute_name, options)
end
# Helper for dealing with association selects/radios, generating the

View File

@ -50,6 +50,51 @@ class InputFieldTest < ActionView::TestCase
assert_no_select 'input.integer[as]'
end
test 'builder input_field should use i18n to translate placeholder text' do
store_translations(:en, :simple_form => { :placeholders => { :user => {
:name => 'Name goes here'
} } }) do
with_concat_form_for(@user) do |f|
f.input_field :name
end
assert_select 'input.string[placeholder=Name goes here]'
end
end
test 'builder input_field should use min_max component' do
with_concat_form_for(@other_validating_user) do |f|
f.input_field :age, :as => :integer
end
assert_select 'input[min=18]'
end
test 'builder input_field should use pattern component' do
with_concat_form_for(@other_validating_user) do |f|
f.input_field :country, :as => :string
end
assert_select 'input[pattern="\w+"]'
end
test 'builder input_field should use readonly component' do
with_concat_form_for(@other_validating_user) do |f|
f.input_field :age, :as => :integer, :readonly => true
end
assert_select 'input.integer.readonly[readonly]'
end
test 'builder input_field should use maxlength component' do
with_concat_form_for(@validating_user) do |f|
f.input_field :name, :as => :string
end
assert_select 'input.string[maxlength=25]'
end
test 'builder collection input_field should generate input tag with a clean HTML' do
with_concat_form_for(@user) do |f|
f.input_field :status, :collection => ['Open', 'Closed'], :class => 'status', :label_method => :to_s, :value_method => :to_s