Skip to content
This repository was archived by the owner on Oct 12, 2019. It is now read-only.

Commit ad4360a

Browse files
committed
Merge pull request #96 from jtomaszewski/patch/remove-timeish-hacks
Remove css hacks in Timeish input
2 parents cb936f1 + 633937e commit ad4360a

File tree

4 files changed

+33
-55
lines changed

4 files changed

+33
-55
lines changed

lib/formtastic-bootstrap/inputs/base/timeish.rb

+20-22
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,50 @@ module FormtasticBootstrap
22
module Inputs
33
module Base
44
module Timeish
5+
FRAGMENT_CLASSES = {
6+
:year => "col-xs-2",
7+
:month => "col-xs-3",
8+
:day => "col-xs-1",
9+
:hour => "col-xs-offset-3 col-xs-1",
10+
:minute => "col-xs-1",
11+
:second => "col-xs-1"
12+
}
513

614
def to_html
7-
form_group_wrapping do
8-
label_html <<
15+
bootstrap_wrapping do
916
hidden_fragments <<
10-
form_control_row_wrapping do
17+
row_wrapping do
1118
fragments.map do |fragment|
12-
fragment_input_html(fragment.to_sym)
19+
fragment_html(fragment.to_sym)
1320
end.join.html_safe
1421
end
1522
end
1623
end
1724

18-
def form_control_row_wrapping(&block)
25+
def row_wrapping(&block)
1926
template.content_tag(:div,
2027
template.capture(&block).html_safe,
21-
form_control_row_wrapper_html_options
28+
:class => 'row'
2229
)
2330
end
2431

25-
def form_control_row_wrapper_html_options
26-
{ :class => "form-control" }
27-
end
28-
29-
def fragment_input_html(fragment)
30-
opts = input_options.merge(:prefix => fragment_prefix, :field_name => fragment_name(fragment), :default => value, :include_blank => include_blank?)
31-
template.send(:"select_#{fragment}", value, opts, fragment_input_html_options(fragment))
32+
def fragment_html(fragment)
33+
template.content_tag(:div, :class => fragment_class(fragment)) do
34+
opts = input_options.merge(:prefix => fragment_prefix, :field_name => fragment_name(fragment), :default => value, :include_blank => include_blank?)
35+
template.send(:"select_#{fragment}", value, opts, fragment_input_html_options(fragment))
36+
end
3237
end
3338

3439
def fragment_input_html_options(fragment)
3540
input_html_options.tap do |options|
3641
options[:id] = fragment_id(fragment)
37-
options[:class] = ((options[:class] || "").split << fragment_class(fragment)).join(" ")
42+
options[:class] = ((options[:class] || "").split << "form-control").join(" ")
3843
options[:placeholder] = fragment_placeholder(fragment)
3944
end
4045
end
4146

4247
def fragment_class(fragment)
43-
{
44-
:year => "col-xs-1",
45-
:month => "col-xs-2",
46-
:day => "col-xs-1",
47-
:hour => "col-xs-1",
48-
:minute => "col-xs-1",
49-
:second => "col-xs-1"
50-
}[fragment]
48+
options[:fragment_classes] || self.class::FRAGMENT_CLASSES[fragment]
5149
end
5250

5351
def fragment_placeholder(fragment)
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
module FormtasticBootstrap
22
module Inputs
33
class DateSelectInput < Formtastic::Inputs::DateSelectInput
4+
FRAGMENT_CLASSES = {
5+
:year => "col-xs-4",
6+
:month => "col-xs-5",
7+
:day => "col-xs-3"
8+
}
9+
410
include Base
511
include Base::Timeish
612
end
713
end
8-
end
14+
end

lib/formtastic-bootstrap/inputs/time_select_input.rb

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
module FormtasticBootstrap
22
module Inputs
33
class TimeSelectInput < Formtastic::Inputs::TimeSelectInput
4+
FRAGMENT_CLASSES = {
5+
:hour => "col-xs-4",
6+
:minute => "col-xs-4",
7+
:secound => "col-xs-4"
8+
}
9+
410
include Base
511
include Base::Timeish
612
end

vendor/assets/stylesheets/formtastic-bootstrap.css

-32
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,3 @@
55
.alert.alert-error > ul.error-list {
66
margin-bottom: 0px;
77
}
8-
9-
10-
/*
11-
** Timeish fixes.
12-
*/
13-
14-
.datetime_select .form-control,
15-
.date_select .form-control,
16-
.time_select .form-control,
17-
.datetime .form-control,
18-
.date .form-control,
19-
.time .form-control
20-
{
21-
border: none;
22-
-webkit-box-shadow: none;
23-
box-shadow: none;
24-
padding: 0px 0px;
25-
}
26-
27-
.datetime_select .form-control select,
28-
.date_select .form-control select,
29-
.time_select .form-control select,
30-
.datetime .form-control select,
31-
.date .form-control select,
32-
.time .form-control select
33-
{
34-
/* This works for me in FireFox but does not work in
35-
Safari or Chrome (31.) If I set a background-color
36-
it will suddenly work in both of those browsers.
37-
*/
38-
height: 34px;
39-
}

0 commit comments

Comments
 (0)