Permalink
Browse files

Adds "form-control" class where required.

This is work to support Bootstrap 3.  In this version "form-control"
is added.

I needed to do some interpretation about how datetime_select and
friends should work.  It sort of works now, but only on FireFox:
WebKit browsers seem to ignore the "height" attribute added in the
CSS.  I might revisit this at some point -- it's pretty annoying.
  • Loading branch information...
1 parent b5eec28 commit 0538a91ba886e54f3bd094f2b39c10ef41e63969 @mjbellantoni committed Nov 24, 2013
@@ -5,6 +5,12 @@ module Html
include Formtastic::Inputs::Base::Html
+ def form_control_input_html_options
+ orig_class = input_html_options[:class]
+ new_class = [orig_class, "form-control"].compact.join(" ")
+ input_html_options.merge(:class => new_class)
+ end
+
def input_html_options
if errors?
{
@@ -7,7 +7,7 @@ module Stringish
def to_html
bootstrap_wrapping do
- builder.text_field(method, input_html_options)
+ builder.text_field(method, form_control_input_html_options)
end
end
@@ -7,16 +7,23 @@ def to_html
form_group_wrapping do
label_html <<
hidden_fragments <<
- fragments.map do |fragment|
- fragment_input_html(fragment.to_sym)
- end.join.html_safe
+ form_control_row_wrapping do
+ fragments.map do |fragment|
+ fragment_input_html(fragment.to_sym)
+ end.join.html_safe
+ end
end
end
- def controls_wrapper_html_options
- super.tap do |options|
- options[:class] = (options[:class].split << "controls-row").join(" ")
- end
+ def form_control_row_wrapping(&block)
+ template.content_tag(:div,
+ template.capture(&block).html_safe,
+ form_control_row_wrapper_html_options
+ )
+ end
+
+ def form_control_row_wrapper_html_options
+ { :class => "form-control" }
end
def fragment_input_html(fragment)
@@ -34,16 +41,17 @@ def fragment_input_html_options(fragment)
def fragment_class(fragment)
{
- :year => "span1",
- :month => "span2",
- :day => "span1",
- :hour => "span1",
- :minute => "span1",
- :second => "span1"
+ :year => "col-xs-1",
+ :month => "col-xs-2",
+ :day => "col-xs-1",
+ :hour => "col-xs-1",
+ :minute => "col-xs-1",
+ :second => "col-xs-1"
}[fragment]
end
def fragment_placeholder(fragment)
+ # TODO This sets a useless placeholer right now.
"." + fragment_class(fragment)
end
@@ -6,7 +6,7 @@ class EmailInput < Formtastic::Inputs::EmailInput
def to_html
bootstrap_wrapping do
- builder.email_field(method, input_html_options)
+ builder.email_field(method, form_control_input_html_options)
end
end
@@ -6,7 +6,7 @@ class NumberInput < Formtastic::Inputs::NumberInput
def to_html
bootstrap_wrapping do
- builder.number_field(method, input_html_options)
+ builder.number_field(method, form_control_input_html_options)
end
end
@@ -6,7 +6,7 @@ class PasswordInput < Formtastic::Inputs::PasswordInput
def to_html
bootstrap_wrapping do
- builder.password_field(method, input_html_options)
+ builder.password_field(method, form_control_input_html_options)
end
end
@@ -6,7 +6,7 @@ class PhoneInput < Formtastic::Inputs::PhoneInput
def to_html
bootstrap_wrapping do
- builder.phone_field(method, input_html_options)
+ builder.phone_field(method, form_control_input_html_options)
end
end
@@ -6,7 +6,7 @@ class RangeInput < Formtastic::Inputs::RangeInput
def to_html
bootstrap_wrapping do
- builder.range_field(method, input_html_options)
+ builder.range_field(method, form_control_input_html_options)
end
end
@@ -6,7 +6,7 @@ class SearchInput < Formtastic::Inputs::SearchInput
def to_html
bootstrap_wrapping do
- builder.search_field(method, input_html_options)
+ builder.search_field(method, form_control_input_html_options)
end
end
@@ -5,6 +5,23 @@ class SelectInput < Formtastic::Inputs::SelectInput
include Base::Collections
include Base::GroupedCollections
+ def select_html
+ builder.select(input_name, collection, input_options, form_control_input_html_options)
+ end
+
+ def grouped_select_html
+ builder.grouped_collection_select(
+ input_name,
+ grouped_collection,
+ group_association,
+ group_label_method,
+ value_method,
+ label_method,
+ input_options,
+ form_control_input_html_options
+ )
+ end
+
def to_html
bootstrap_wrapping do
options[:group_by] ? grouped_select_html : select_html
@@ -2,10 +2,10 @@ module FormtasticBootstrap
module Inputs
class TextInput < Formtastic::Inputs::TextInput
include Base
-
+
def to_html
bootstrap_wrapping do
- builder.text_area(method, input_html_options)
+ builder.text_area(method, form_control_input_html_options)
end
end
@@ -6,7 +6,7 @@ class UrlInput < Formtastic::Inputs::UrlInput
def to_html
bootstrap_wrapping do
- builder.url_field(method, input_html_options)
+ builder.url_field(method, form_control_input_html_options)
end
end
end
@@ -5,3 +5,35 @@
.alert.alert-error > ul.error-list {
margin-bottom: 0px;
}
+
+
+/*
+** Timeish fixes.
+*/
+
+.datetime_select .form-control,
+.date_select .form-control,
+.time_select .form-control,
+.datetime .form-control,
+.date .form-control,
+.time .form-control
+ {
+ border: none;
+ -webkit-box-shadow: none;
+ box-shadow: none;
+ padding: 0px 0px;
+}
+
+.datetime_select .form-control select,
+.date_select .form-control select,
+.time_select .form-control select,
+.datetime .form-control select,
+.date .form-control select,
+.time .form-control select
+{
+ /* This works for me in FireFox but does not work in
+ Safari or Chrome (31.) If I set a background-color
+ it will suddenly work in both of those browsers.
+ */
+ height: 34px;
+}

0 comments on commit 0538a91

Please sign in to comment.