Browse files

add components that don't generate tags for input_field

closes #632
  • Loading branch information...
1 parent 82c0a52 commit 92585eb25e13693eecb478edc4882ecb9954d24a @nashby committed Jul 22, 2012
Showing with 46 additions and 1 deletion.
  1. +1 −1 lib/simple_form/form_builder.rb
  2. +45 −0 test/form_builder/input_field_test.rb
View
2 lib/simple_form/form_builder.rb
@@ -133,7 +133,7 @@ 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)
- 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
45 test/form_builder/input_field_test.rb
@@ -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 92585eb

Please sign in to comment.