Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

add components that don't generate tags for input_field #633

Closed
wants to merge 1 commit into from

4 participants

@nashby
Collaborator

closes #632

@rafaelfranca

Yes, seems good. Moving the discussion to here.

cc/ @josevalim @carlosantoniodasilva

@josevalim
Owner

Maybe we could have a way to mark if a component is part of the input (like placeholder) or not. This way, we could ask the current wrapper: "hey bro, which components that you have are extensions to the input?", then it would, "yo dawg, here they are" and then we could reuse them on this code. It should not be hard after all, because such components are not nested (they are usually direct children from the root).

@nashby
Collaborator

@josevalim is adding a method like input_extension? to components sounds ok to you?

@josevalim
Owner
@nashby
Collaborator

@josevalim if I add method input_extension? to all components how should I call this method if I only have that components as a list of symbols [:placeholder, :min_max, ...]? Should I constantize it and call Placeholders.input_extension? or something like that?

@josevalim
Owner

@nashby uh-oh. Not sure. Constantize does not seem a good idea, @rafaelfranca any ideas?

@rafaelfranca

Not sure. Maybe a method in the wrapper that returns all the component that are extensions

module SimpleForm
  module Wrappers
    class Many
      INPUT_EXTENSIONS = [:min_max, :maxlength, :placeholder, :pattern, :readonly]

      def input_extension
       @components - INPUT_EXTENSIONS
      end
    end
  end
end
@nashby
Collaborator

@carlosantoniodasilva hey bro, maybe you have some thoughts on this?

@carlosantoniodasilva
Collaborator

Sorry guys, I'm kinda late on this email thing:

Screen Shot 2013-01-29 at 12 30 44 AM

I think it's fine to go as-is for now, and it can be merged to both 2.1 and master branches, with a changelog entry. Just make sure the master branch has the hashes a-la 1.9 style.

We can discuss a few different possibilities tomorrow, but it can be merged without waiting for that. Thanks @nashby.

@nashby
Collaborator

closed via b0e8d1f

@nashby nashby closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 22, 2012
  1. @nashby
This page is out of date. Refresh to see the latest.
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
Something went wrong with that request. Please try again.