Permalink
Browse files

Merge pull request #99 from jtomaszewski/patch/bootstrap3-input-group

Fix .input-group to be working in bootstrap 3.x.
  • Loading branch information...
2 parents 5a26414 + b5f3553 commit dde58230285a6c604b0f30ef535316e04c09616a @sodabrew sodabrew committed Feb 13, 2014
Showing with 42 additions and 37 deletions.
  1. +21 −16 lib/formtastic-bootstrap/inputs/base/wrapping.rb
  2. +21 −21 spec/inputs/base/wrapping_spec.rb
View
37 lib/formtastic-bootstrap/inputs/base/wrapping.rb
@@ -6,24 +6,29 @@ module Wrapping
include Formtastic::Inputs::Base::Wrapping
def bootstrap_wrapping(&block)
- input_content = [
+ form_group_wrapping do
+ label_html <<
+ template.content_tag(:span, :class => 'form-wrapper') do
+ input_content(&block) <<
+ hint_html <<
+ error_html(:block)
+ end
+ end
+ end
+
+ def input_content(&block)
+ content = [
add_on_content(options[:prepend]),
options[:prepend_content],
yield,
add_on_content(options[:append]),
- options[:append_content],
- hint_html
+ options[:append_content]
].compact.join("\n").html_safe
- form_group_wrapping do
- label_html <<
- if prepended_or_appended?(options)
- template.content_tag(:div, :class => add_on_wrapper_classes(options).join(" ")) do
- input_content
- end
- else
- input_content
- end
+ if prepended_or_appended?(options)
+ template.content_tag(:div, content, :class => add_on_wrapper_classes(options).join(" "))
+ else
+ content
end
end
@@ -33,7 +38,7 @@ def prepended_or_appended?(options)
def add_on_content(content)
return nil unless content
- template.content_tag(:span, content, :class => 'add-on')
+ template.content_tag(:span, content, :class => 'input-group-addon')
end
def form_group_wrapping(&block)
@@ -51,9 +56,9 @@ def wrapper_html_options
end
def add_on_wrapper_classes(options)
- [:prepend, :append, :prepend_content, :append_content].map do |key|
- "input-#{key.to_s.gsub('_content', '')}" if options[key]
- end
+ [:prepend, :append, :prepend_content, :append_content].find do |key|
+ options.has_key?(key)
+ end ? ['input-group'] : []
end
end
View
42 spec/inputs/base/wrapping_spec.rb
@@ -14,29 +14,29 @@
describe "text add ons" do
context "when appened with append option" do
- let(:options) { { :append => "text appended in add-on"} }
+ let(:options) { { :append => "text appended in addon"} }
- it "should have the appended text to the input in an add-on span" do
- output_buffer.should have_tag("form div.input-append span.add-on", "text appended in add-on")
- output_buffer.should_not have_tag("form div.input-prepend")
+ it "should have the appended text to the input in an addon span" do
+ output_buffer.should have_tag("form div.input-group span.input-group-addon", "text appended in addon")
+ output_buffer.should_not have_tag("form div.input-group")
end
end
context "when prepended with prepend option" do
- let(:options) { { :prepend => "text prepended in add-on"} }
+ let(:options) { { :prepend => "text prepended in addon"} }
- it "should have the prepended text to the input in an add-on span" do
- output_buffer.should have_tag("form div.input-prepend span.add-on", "text prepended in add-on")
- output_buffer.should_not have_tag("form div.input-append")
+ it "should have the prepended text to the input in an addon span" do
+ output_buffer.should have_tag("form div.input-group span.input-group-addon", "text prepended in addon")
+ output_buffer.should_not have_tag("form div.input-group")
end
end
context "when prepended and appened with prepend and append options" do
- let(:options) { { :prepend => "text prepended in add-on", :append => "text appended in add-on"} }
+ let(:options) { { :prepend => "text prepended in addon", :append => "text appended in addon"} }
- it "should have the prepended text to the input in an add-on span" do
- output_buffer.should have_tag("form div.input-append span.add-on", "text appended in add-on")
- output_buffer.should have_tag("form div.input-prepend span.add-on", "text prepended in add-on")
+ it "should have the prepended text to the input in an addon span" do
+ output_buffer.should have_tag("form div.input-group span.input-group-addon", "text appended in addon")
+ output_buffer.should have_tag("form div.input-group span.input-group-addon", "text prepended in addon")
end
end
end
@@ -45,27 +45,27 @@
context "when appended with append_content option" do
let(:options) { { :append_content => content_tag(:a, "button appended", :class => "btn")} }
- it "should have the appended text to the input in an add-on span" do
- output_buffer.should have_tag("form div.input-append a.btn", "button appended")
- output_buffer.should_not have_tag("form div.input-append span.add-on")
+ it "should have the appended text to the input in an addon span" do
+ output_buffer.should have_tag("form div.input-group a.btn", "button appended")
+ output_buffer.should_not have_tag("form div.input-group span.input-group-addon")
end
end
context "when prepended with prepend_content option" do
let(:options) { { :prepend_content => content_tag(:a, "button prepended", :class => "btn")} }
- it "should have the prepended text to the input in an add-on span" do
- output_buffer.should have_tag("form div.input-prepend a.btn", "button prepended")
- output_buffer.should_not have_tag("form div.input-prepend span.add-on")
+ it "should have the prepended text to the input in an addon span" do
+ output_buffer.should have_tag("form div.input-group a.btn", "button prepended")
+ output_buffer.should_not have_tag("form div.input-group span.input-group-addon")
end
end
context "when prepended and appened with prepend and append options" do
let(:options) { { :prepend_content => content_tag(:a, "button prepended", :class => "btn"), :append_content => content_tag(:a, "button appended", :class => "btn")} }
- it "should have the prepended text to the input in an add-on span" do
- output_buffer.should have_tag("form div.input-prepend a.btn", "button prepended")
- output_buffer.should have_tag("form div.input-append a.btn", "button appended")
+ it "should have the prepended text to the input in an addon span" do
+ output_buffer.should have_tag("form div.input-group a.btn", "button prepended")
+ output_buffer.should have_tag("form div.input-group a.btn", "button appended")
end
end

0 comments on commit dde5823

Please sign in to comment.