Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implement HiddenInpute.

  • Loading branch information...
commit 3ef64c4929d65a3951945529f973b37a2cc5073a 1 parent 28daa8d
@mjbellantoni authored
View
2  lib/formtastic-bootstrap/inputs.rb
@@ -14,7 +14,7 @@ module Inputs
autoload :DatetimeSelectInput, "formtastic-bootstrap/inputs/datetime_select_input"
autoload :EmailInput, "formtastic-bootstrap/inputs/email_input"
autoload :FileInput, "formtastic-bootstrap/inputs/file_input"
- # autoload :HiddenInput
+ autoload :HiddenInput, "formtastic-bootstrap/inputs/hidden_input"
# autoload :NumberInput
# autoload :NumericInput
# autoload :PasswordInput
View
2  lib/formtastic-bootstrap/inputs/hidden_input.rb
@@ -3,7 +3,7 @@ module Inputs
class HiddenInput < Formtastic::Inputs::HiddenInput
include Base
def to_html
- generic_input_wrapping do
+ bootstrap_wrapping do
builder.hidden_field(method, input_html_options)
end
end
View
95 spec/inputs/hidden_input_spec.rb
@@ -8,61 +8,62 @@
before do
@output_buffer = ''
mock_everything
- Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
-
- concat(semantic_form_for(@new_post) do |builder|
- concat(builder.input(:secret, :as => :hidden))
- concat(builder.input(:author_id, :as => :hidden, :value => 99))
- concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
- concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
- concat(builder.input(:author, :as => :hidden, :value => 'direct_value', :input_html => {:value => "formtastic_value"}))
- end)
+
+ with_deprecation_silenced do
+ concat(semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:secret, :as => :hidden))
+ concat(builder.input(:author_id, :as => :hidden, :value => 99))
+ concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
+ concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
+ concat(builder.input(:author, :as => :hidden, :value => 'direct_value', :input_html => {:value => "formtastic_value"}))
+ end)
+ end
end
+ it_should_have_bootstrap_horizontal_wrapping
it_should_have_input_wrapper_with_class("hidden")
- it_should_have_input_wrapper_with_class(:clearfix)
- it_should_have_input_class_in_the_right_place
+ it_should_have_input_wrapper_with_class(:input)
it_should_have_input_wrapper_with_id("post_secret_input")
it_should_not_have_a_label
it "should generate a input field" do
- output_buffer.should have_tag("form div.clearfix div.input input#post_secret")
- output_buffer.should have_tag("form div.clearfix div.input input#post_secret[@type=\"hidden\"]")
- output_buffer.should have_tag("form div.clearfix div.input input#post_secret[@name=\"post[secret]\"]")
+ output_buffer.should have_tag("form div.control-group div.controls input#post_secret")
+ output_buffer.should have_tag("form div.control-group div.controls input#post_secret[@type=\"hidden\"]")
+ output_buffer.should have_tag("form div.control-group div.controls input#post_secret[@name=\"post[secret]\"]")
end
it "should get value from the object" do
- output_buffer.should have_tag("form div.clearfix div.input input#post_secret[@type=\"hidden\"][@value=\"1\"]")
+ output_buffer.should have_tag("form div.control-group div.controls input#post_secret[@type=\"hidden\"][@value=\"1\"]")
end
it "should pass any explicitly specified value - using :value" do
- output_buffer.should have_tag("form div.clearfix div.input input#post_author_id[@type=\"hidden\"][@value=\"99\"]")
+ output_buffer.should have_tag("form div.control-group div.controls input#post_author_id[@type=\"hidden\"][@value=\"99\"]")
end
# Handle Formtastic :input_html options for consistency.
it "should pass any explicitly specified value - using :input_html options" do
- output_buffer.should have_tag("form div.clearfix div.input input#post_published[@type=\"hidden\"][@value=\"true\"]")
+ output_buffer.should have_tag("form div.control-group div.controls input#post_published[@type=\"hidden\"][@value=\"true\"]")
end
it "should pass any option specified using :input_html" do
- output_buffer.should have_tag("form div.clearfix div.input input#new_post_reviewer[@type=\"hidden\"][@class=\"new_post_reviewer\"]")
+ output_buffer.should have_tag("form div.control-group div.controls input#new_post_reviewer[@type=\"hidden\"][@class=\"new_post_reviewer\"]")
end
it "should prefer :input_html over directly supplied options" do
- output_buffer.should have_tag("form div.clearfix div.input input#post_author_id[@type=\"hidden\"][@value=\"formtastic_value\"]")
+ output_buffer.should have_tag("form div.control-group div.controls input#post_author_id[@type=\"hidden\"][@value=\"formtastic_value\"]")
end
it "should not render inline errors" do
@errors = mock('errors')
- @errors.stub!(:[]).with(:secret).and_return(["foo", "bah"])
+ @errors.stub!(:[]).with(errors_matcher(:secret)).and_return(["foo", "bah"])
@new_post.stub!(:errors).and_return(@errors)
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:secret, :as => :hidden))
end)
- output_buffer.should_not have_tag("form li p.inline-errors")
- output_buffer.should_not have_tag("form li ul.errors")
+ output_buffer.should_not have_tag("form div.control-group div.controls p.inline-errors")
+ output_buffer.should_not have_tag("form div.control-group div.controls ul.errors")
end
it "should not render inline hints" do
@@ -70,8 +71,8 @@
concat(builder.input(:secret, :as => :hidden, :hint => "all your base are belong to use"))
end)
- output_buffer.should_not have_tag("form li p.inline-hints")
- output_buffer.should_not have_tag("form li ul.hints")
+ output_buffer.should_not have_tag("form div.control-group div.controls p.inline-hints")
+ output_buffer.should_not have_tag("form div.control-group div.controls ul.hints")
end
describe "when namespace is provided" do
@@ -79,14 +80,16 @@
before do
@output_buffer = ''
mock_everything
-
- concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
- concat(builder.input(:secret, :as => :hidden))
- concat(builder.input(:author_id, :as => :hidden, :value => 99))
- concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
- concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
- concat(builder.input(:author, :as => :hidden, :value => 'direct_value', :input_html => {:value => "formtastic_value"}))
- end)
+
+ with_deprecation_silenced do
+ concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
+ concat(builder.input(:secret, :as => :hidden))
+ concat(builder.input(:author_id, :as => :hidden, :value => 99))
+ concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
+ concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
+ concat(builder.input(:author, :as => :hidden, :value => 'direct_value', :input_html => {:value => "formtastic_value"}))
+ end)
+ end
end
attributes_to_check = [:secret, :author_id, :published, :reviewer]
@@ -100,6 +103,34 @@
end
+ describe "when index is provided" do
+
+ before do
+ @output_buffer = ''
+ mock_everything
+
+ concat(semantic_form_for(@new_post) do |builder|
+ concat(builder.fields_for(:author, :index => 3) do |author|
+ concat(author.input(:name, :as => :hidden))
+ end)
+ end)
+ end
+
+ it 'should index the id of the control group' do
+ output_buffer.should have_tag("div.control-group#post_author_attributes_3_name_input")
+ end
+
+ it 'should index the id of the select tag' do
+ output_buffer.should have_tag("input#post_author_attributes_3_name")
+ end
+
+ it 'should index the name of the select tag' do
+ output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
+ end
+
+ end
+
+
context "when required" do
it "should not add the required attribute to the input's html options" do
concat(semantic_form_for(@new_post) do |builder|
Please sign in to comment.
Something went wrong with that request. Please try again.