Permalink
Browse files

add components that don't generate tags for input_field

closes #632

Conflicts:

	lib/simple_form/form_builder.rb

Conflicts:

	lib/simple_form/form_builder.rb
  • Loading branch information...
1 parent b98dd62 commit b0e8d1f70c5cabf4db3ca5ae94912f81ff4965a2 @nashby nashby committed Jul 22, 2012
Showing with 50 additions and 1 deletion.
  1. +4 −0 CHANGELOG.md
  2. +1 −1 lib/simple_form/form_builder.rb
  3. +45 −0 test/form_builder/input_field_test.rb
View
@@ -9,6 +9,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.
@@ -138,7 +138,7 @@ def input_field(attribute_name, options={})
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
@@ -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

0 comments on commit b0e8d1f

Please sign in to comment.