Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix .input-group to be working in bootstrap 3.x. #99

Merged
merged 2 commits into from

2 participants

@jtomaszewski
Collaborator

This replaces old .input-append or .input-prepend classes to .input-group which are being used in Bootstrap 3.x.

@sodabrew sodabrew merged commit dde5823 into mjbellantoni:master
@sodabrew
Collaborator

Looks good to me. Thank you!

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