Permalink
Browse files

Added :as => :hidden support.

  • Loading branch information...
josevalim committed May 20, 2009
1 parent b477312 commit 2e9e7c5a63140e835c77a612489c16d05cd095f7
Showing with 46 additions and 2 deletions.
  1. +1 −0 README.textile
  2. +6 −1 generators/formtastic_stylesheets/templates/formtastic.css
  3. +9 −0 lib/formtastic.rb
  4. +30 −1 spec/formtastic_spec.rb
View
@@ -240,6 +240,7 @@ h2. The Available Inputs
* :numeric (a text field, like string) - default for :integer, :float and :decimal column types
* :file (a file field) - default for paperclip or attachment_fu attributes
* :country (a select menu of country names) - default for :string columns named "country", requires a country_select plugin to be installed
+* :hidden (a hidden field) - creates a hidden field (added for compatibility)
The documentation is pretty good for each of these (what it does, what the output is, what the options are, etc) so go check it out.
@@ -91,7 +91,12 @@ form.formtastic fieldset ol li.numeric input { width:74%; }
form.formtastic fieldset ol li.text textarea { width:74%; }
-/* CHECKBOX OVERRIDES
+/* HIDDEN OVERRIDES
+--------------------------------------------------------------------------------------------------*/
+form.formtastic fieldset ol li.hidden { display:none; }
+
+
+/* BOOLEAN OVERRIDES
--------------------------------------------------------------------------------------------------*/
form.formtastic fieldset ol li.boolean label { padding-left:25%; width:auto; }
form.formtastic fieldset ol li.boolean label input { margin:0 0.5em 0 0.2em; }
View
@@ -67,6 +67,7 @@ class SemanticFormBuilder < ActionView::Helpers::FormBuilder
# * :string (a text field) - default for :string column types
# * :numeric (a text field, like string) - default for :integer, :float and :decimal column types
# * :country (a select menu of country names) - requires a country_select plugin to be installed
+ # * :hidden (a hidden field) - creates a hidden field (added for compatibility)
#
# Example:
#
@@ -456,6 +457,14 @@ def input_simple(type, method, options)
self.send(INPUT_MAPPINGS[type], method, html_options)
end
+ # Outputs a hidden field inside the wrapper, which should be hidden with CSS.
+ # Additionals options can be given and will be sent straight to hidden input
+ # element.
+ #
+ def hidden_input(method, options)
+ self.hidden_field(method, set_options(options))
+ end
+
# Outputs a label and a select box containing options from the parent
# (belongs_to, has_many, has_and_belongs_to_many) association. If an association
# is has_many or has_and_belongs_to_many the select box will be set as multi-select
View
@@ -666,7 +666,7 @@ def custom(arg1, arg2, options = {})
end
it 'should call the corresponding input method' do
- [:select, :time_zone, :radio, :date, :datetime, :time, :boolean, :check_boxes].each do |input_style|
+ [:select, :time_zone, :radio, :date, :datetime, :time, :boolean, :check_boxes, :hidden].each do |input_style|
@new_post.stub!(:generic_column_name)
@new_post.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
semantic_form_for(@new_post) do |builder|
@@ -1078,6 +1078,35 @@ def custom(arg1, arg2, options = {})
end
end
+ describe ":as => :hidden" do
+ before do
+ @new_post.stub!(:hidden)
+ @new_post.stub!(:column_for_attribute).and_return(mock('column', :type => :string))
+
+ semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:hidden, :as => :hidden))
+ end
+ end
+
+ it "should have a hidden class on the wrapper" do
+ output_buffer.should have_tag('form li.hidden')
+ end
+
+ it 'should have a post_hidden_input id on the wrapper' do
+ output_buffer.should have_tag('form li#post_hidden_input')
+ end
+
+ it 'should not generate a label for the input' do
+ output_buffer.should_not have_tag('form li label')
+ end
+
+ it "should generate a input field" do
+ output_buffer.should have_tag("form li input#post_hidden")
+ output_buffer.should have_tag("form li input[@type=\"hidden\"]")
+ output_buffer.should have_tag("form li input[@name=\"post[hidden]\"]")
+ end
+ end
+
describe ":as => :time_zone" do
before do
@new_post.stub!(:time_zone)

3 comments on commit 2e9e7c5

@justinfrench

This comment has been minimized.

Show comment Hide comment
@justinfrench

justinfrench May 20, 2009

Owner

awesome!

Owner

justinfrench replied May 20, 2009

awesome!

@grimen

This comment has been minimized.

Show comment Hide comment
@grimen

grimen May 20, 2009

Contributor

high five

Contributor

grimen replied May 20, 2009

high five

@gregf

This comment has been minimized.

Show comment Hide comment
@gregf

gregf May 20, 2009

nice :)

nice :)

Please sign in to comment.