Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: justinfrench/formtastic
...
head fork: rgarner/formtastic
Checking mergeability… Don’t worry, you can still create the pull request.
  • 5 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
Commits on Sep 17, 2010
@justinfrench string|numeric|password and other basic inputs no longer add a size a…
…ttribute based of the column data -- the default config is applied, unless it's nil
b560e60
@justinfrench default text field size is now nil instead of 50, in practice that me…
…ans it will be ommitted from most inputs, which makes styling easier, and custom sizes with the size attribute more deliberate
18dcc58
@justinfrench * style inputs with { width:75% } by default
* style inputs with a size attribute with { width:auto; max-width:74%; } so that a small size attribute (eg 3) will make the box smaller, and a large size attribute (eg 255) won't bust a layout
a9aab66
@justinfrench text inputs no longer include a default cols attribute, specify it wi…
…th :input_html if you need it, but the value we were using was useless... also beefed up spec coverage
c012f06
@justinfrench text input css behaviour updated to be similar to string etc 54b6284
View
7 generators/formtastic/templates/formtastic.css
@@ -79,12 +79,17 @@ form.formtastic fieldset > ol > li ul.errors li { padding:0; border:none; displa
--------------------------------------------------------------------------------------------------*/
form.formtastic fieldset > ol > li.string input,
form.formtastic fieldset > ol > li.password input,
-form.formtastic fieldset > ol > li.numeric input { max-width:72%; }
+form.formtastic fieldset > ol > li.numeric input { width:72%; }
+
+form.formtastic fieldset > ol > li.string input[size],
+form.formtastic fieldset > ol > li.password input[size],
+form.formtastic fieldset > ol > li.numeric input[size] { width:auto; max-width:72%; }
/* TEXTAREA OVERRIDES
--------------------------------------------------------------------------------------------------*/
form.formtastic fieldset > ol > li.text textarea { width:72%; }
+form.formtastic fieldset > ol > li.text textarea[cols] { width:auto; max-width:72%; }
/* HIDDEN OVERRIDES
View
2  generators/formtastic/templates/formtastic.rb
@@ -1,4 +1,4 @@
-# Set the default text field size when input is a string. Default is 50.
+# Set the default text field size when input is a string. Default is nil.
# Formtastic::SemanticFormBuilder.default_text_field_size = 50
# Set the default text area height when input is a text. Default is 20.
View
6 lib/formtastic.rb
@@ -11,7 +11,7 @@ class SemanticFormBuilder < ActionView::Helpers::FormBuilder
:inline_order, :file_methods, :priority_countries, :i18n_lookups_by_default, :escape_html_entities_in_hints_and_labels, :default_commit_button_accesskey,
:instance_reader => false
- self.default_text_field_size = 50
+ self.default_text_field_size = nil
self.default_text_area_height = 20
self.all_fields_required_by_default = true
self.include_blank_for_select_by_default = true
@@ -1626,12 +1626,12 @@ def default_string_options(method, type) #:nodoc:
column = self.column_for(method)
if type == :text
- { :cols => self.class.default_text_field_size, :rows => self.class.default_text_area_height }
+ { :rows => self.class.default_text_area_height }
elsif type == :numeric || column.nil? || column.limit.nil?
{ :size => self.class.default_text_field_size }
else
{ :maxlength => column.limit,
- :size => self.class.default_text_field_size && [column.limit, self.class.default_text_field_size].min }
+ :size => self.class.default_text_field_size }
end
end
View
3  spec/inputs/numeric_input_spec.rb
@@ -21,7 +21,8 @@
it_should_have_input_with_id("post_title")
it_should_have_input_with_type(:text)
it_should_have_input_with_name("post[title]")
- it_should_use_default_text_field_size_when_method_has_no_database_column(:string)
+ it_should_use_default_text_field_size_when_not_nil(:string)
+ it_should_not_use_default_text_field_size_when_nil(:string)
it_should_apply_custom_input_attributes_when_input_html_provided(:string)
it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
it_should_apply_error_logic_for_input_type(:numeric)
View
5 spec/inputs/password_input_spec.rb
@@ -22,9 +22,8 @@
it_should_have_input_with_type(:password)
it_should_have_input_with_name("post[title]")
it_should_have_maxlength_matching_column_limit
- it_should_use_default_text_field_size_for_columns_longer_than_default_text_field_size(:string)
- it_should_use_column_size_for_columns_shorter_than_default_text_field_size(:string)
- it_should_use_default_text_field_size_when_method_has_no_database_column(:string)
+ it_should_use_default_text_field_size_when_not_nil(:string)
+ it_should_not_use_default_text_field_size_when_nil(:string)
it_should_apply_custom_input_attributes_when_input_html_provided(:string)
it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
it_should_apply_error_logic_for_input_type(:password)
View
5 spec/inputs/string_input_spec.rb
@@ -25,9 +25,8 @@
it_should_have_input_with_type(:text)
it_should_have_input_with_name("post[title]")
it_should_have_maxlength_matching_column_limit
- it_should_use_default_text_field_size_for_columns_longer_than_default_text_field_size(:string)
- it_should_use_column_size_for_columns_shorter_than_default_text_field_size(:string)
- it_should_use_default_text_field_size_when_method_has_no_database_column(:string)
+ it_should_use_default_text_field_size_when_not_nil(:string)
+ it_should_not_use_default_text_field_size_when_nil(:string)
it_should_apply_custom_input_attributes_when_input_html_provided(:string)
it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
it_should_apply_error_logic_for_input_type(:string)
View
56 spec/inputs/text_input_spec.rb
@@ -29,6 +29,62 @@
output_buffer.concat(form) if Formtastic::Util.rails3?
output_buffer.should have_tag("form li textarea.myclass")
end
+
+ it "should have a cols attribute when :cols is specified in :input_html" do
+ form = semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:title, :as => :text, :input_html => { :cols => 42 }))
+ end
+ output_buffer.concat(form) if Formtastic::Util.rails3?
+ output_buffer.should have_tag("form li textarea[@cols='42']")
+ end
+
+ it "should not have a cols attribute when :cols is missing in :input_html" do
+ form = semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:title, :as => :text, :input_html => { :cols => nil }))
+ end
+ output_buffer.concat(form) if Formtastic::Util.rails3?
+ output_buffer.should_not have_tag("form li textarea[@cols]")
+ end
+
+ it "should have a rows attribute when :rows is specified in :input_html as a number" do
+ form = semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:title, :as => :text, :input_html => { :rows => 42 }))
+ end
+ output_buffer.concat(form) if Formtastic::Util.rails3?
+ output_buffer.should have_tag("form li textarea[@rows='42']")
+
+ end
+
+ it "should not have a rows attribute when :rows is specified in :input_html as nil" do
+ form = semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:title, :as => :text, :input_html => { :rows => nil }))
+ end
+ output_buffer.concat(form) if Formtastic::Util.rails3?
+ output_buffer.should_not have_tag("form li textarea[@rows]")
+ end
+
+ context "when :rows is missing in :input_html" do
+ it "should have a rows attribute matching default_text_area_height if numeric" do
+ with_config :default_text_area_height, 12 do
+ form = semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:title, :as => :text))
+ end
+ output_buffer.concat(form) if Formtastic::Util.rails3?
+ output_buffer.should have_tag("form li textarea[@rows='12']")
+ end
+ end
+
+ it "should not have a rows attribute if default_text_area_height is nil" do
+ with_config :default_text_area_height, nil do
+ form = semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:title, :as => :text))
+ end
+ output_buffer.concat(form) if Formtastic::Util.rails3?
+ output_buffer.should_not have_tag("form li textarea[@rows]")
+ end
+
+ end
+ end
end
View
55 spec/support/custom_macros.rb
@@ -83,15 +83,28 @@ def it_should_have_textarea_with_id(element_id)
end
end
- def it_should_use_default_text_field_size_when_method_has_no_database_column(as)
- it 'should use default_text_field_size when method has no database column' do
- @new_post.stub!(:column_for_attribute).and_return(nil) # Return a nil column
-
- form = semantic_form_for(@new_post) do |builder|
- concat(builder.input(:title, :as => as))
+ def it_should_use_default_text_field_size_when_not_nil(as)
+ it 'should use default_text_field_size when not nil' do
+ with_config :default_text_field_size, 30 do
+ form = semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:title, :as => as))
+ end
+ output_buffer.concat(form) if Formtastic::Util.rails3?
+ output_buffer.should have_tag("form li input[@size='#{Formtastic::SemanticFormBuilder.default_text_field_size}']")
+ end
+ end
+ end
+
+ def it_should_not_use_default_text_field_size_when_nil(as)
+ it 'should not use default_text_field_size when nil' do
+ with_config :default_text_field_size, nil do
+ form = semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:title, :as => as))
+ end
+ output_buffer.concat(form) if Formtastic::Util.rails3?
+ output_buffer.should have_tag("form li input")
+ output_buffer.should_not have_tag("form li input[@size]")
end
- output_buffer.concat(form) if Formtastic::Util.rails3?
- output_buffer.should have_tag("form li input[@size='#{Formtastic::SemanticFormBuilder.default_text_field_size}']")
end
end
@@ -123,19 +136,19 @@ def it_should_have_maxlength_matching_column_limit
end
end
- def it_should_use_default_text_field_size_for_columns_longer_than_default_text_field_size(as)
- it 'should use default_text_field_size for columns longer than default_text_field_size' do
- default_size = Formtastic::SemanticFormBuilder.default_text_field_size
- @new_post.stub!(:column_for_attribute).and_return(mock('column', :type => as, :limit => default_size * 2))
-
- form = semantic_form_for(@new_post) do |builder|
- concat(builder.input(:title, :as => as))
- end
-
- output_buffer.concat(@form) if Formtastic::Util.rails3?
- output_buffer.should have_tag("form li input[@size='#{default_size}']")
- end
- end
+ #def it_should_use_default_text_field_size_for_columns_longer_than_default_text_field_size(as)
+ # it 'should use default_text_field_size for columns longer than default_text_field_size' do
+ # default_size = Formtastic::SemanticFormBuilder.default_text_field_size
+ # @new_post.stub!(:column_for_attribute).and_return(mock('column', :type => as, :limit => default_size * 2))
+ #
+ # form = semantic_form_for(@new_post) do |builder|
+ # concat(builder.input(:title, :as => as))
+ # end
+ #
+ # output_buffer.concat(@form) if Formtastic::Util.rails3?
+ # output_buffer.should have_tag("form li input[@size='#{default_size}']")
+ # end
+ #end
def it_should_use_column_size_for_columns_shorter_than_default_text_field_size(as)
it 'should use the column size for columns shorter than default_text_field_size' do

No commit comments for this range

Something went wrong with that request. Please try again.