formtastic 2.1.1 → 2.2.0.rc
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.travis.yml +19 -1
- data/Appraisals +7 -0
- data/CHANGELOG +18 -0
- data/README.textile +14 -16
- data/formtastic.gemspec +1 -1
- data/gemfiles/rails-4.gemfile +8 -0
- data/lib/formtastic/form_builder.rb +0 -1
- data/lib/formtastic/helpers/input_helper.rb +12 -26
- data/lib/formtastic/inputs.rb +6 -0
- data/lib/formtastic/inputs/base.rb +16 -4
- data/lib/formtastic/inputs/base/datetime_pickerish.rb +85 -0
- data/lib/formtastic/inputs/base/stringish.rb +10 -2
- data/lib/formtastic/inputs/base/timeish.rb +17 -17
- data/lib/formtastic/inputs/base/wrapping.rb +25 -20
- data/lib/formtastic/inputs/boolean_input.rb +24 -1
- data/lib/formtastic/inputs/date_input.rb +5 -29
- data/lib/formtastic/inputs/date_picker_input.rb +93 -0
- data/lib/formtastic/inputs/date_select_input.rb +34 -0
- data/lib/formtastic/inputs/datetime_input.rb +6 -8
- data/lib/formtastic/inputs/datetime_picker_input.rb +100 -0
- data/lib/formtastic/inputs/datetime_select_input.rb +12 -0
- data/lib/formtastic/inputs/hidden_input.rb +1 -1
- data/lib/formtastic/inputs/radio_input.rb +1 -1
- data/lib/formtastic/inputs/select_input.rb +2 -5
- data/lib/formtastic/inputs/time_input.rb +4 -28
- data/lib/formtastic/inputs/time_picker_input.rb +99 -0
- data/lib/formtastic/inputs/time_select_input.rb +34 -0
- data/lib/formtastic/version.rb +1 -1
- data/lib/generators/templates/formtastic.rb +0 -8
- data/sample/basic_inputs.html +21 -1
- data/spec/builder/semantic_fields_for_spec.rb +1 -1
- data/spec/generators/formtastic/install/install_generator_spec.rb +1 -1
- data/spec/helpers/input_helper_spec.rb +20 -16
- data/spec/helpers/semantic_errors_helper_spec.rb +10 -10
- data/spec/inputs/custom_input_spec.rb +5 -2
- data/spec/inputs/date_picker_input_spec.rb +449 -0
- data/spec/inputs/{date_input_spec.rb → date_select_input_spec.rb} +34 -34
- data/spec/inputs/datetime_picker_input_spec.rb +490 -0
- data/spec/inputs/{datetime_input_spec.rb → datetime_select_input_spec.rb} +33 -33
- data/spec/inputs/deprecated_time_date_datetime_inputs_spec.rb +48 -0
- data/spec/inputs/hidden_input_spec.rb +21 -17
- data/spec/inputs/include_blank_spec.rb +3 -3
- data/spec/inputs/label_spec.rb +1 -1
- data/spec/inputs/placeholder_spec.rb +1 -1
- data/spec/inputs/select_input_spec.rb +22 -14
- data/spec/inputs/time_picker_input_spec.rb +455 -0
- data/spec/inputs/{time_input_spec.rb → time_select_input_spec.rb} +35 -35
- data/spec/spec_helper.rb +25 -1
- data/spec/support/custom_macros.rb +2 -2
- metadata +32 -21
- data/lib/formtastic/helpers/buttons_helper.rb +0 -310
- data/spec/helpers/buttons_helper_spec.rb +0 -166
- data/spec/helpers/commit_button_helper_spec.rb +0 -530
@@ -14,29 +14,34 @@ module Formtastic
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def wrapper_html_options
|
17
|
-
opts =
|
18
|
-
opts[:class] =
|
19
|
-
|
20
|
-
when Array
|
21
|
-
opts[:class].dup
|
22
|
-
when nil
|
23
|
-
[]
|
24
|
-
else
|
25
|
-
[opts[:class].to_s]
|
26
|
-
end
|
27
|
-
opts[:class] << as
|
28
|
-
opts[:class] << "input"
|
29
|
-
opts[:class] << "error" if errors?
|
30
|
-
opts[:class] << "optional" if optional?
|
31
|
-
opts[:class] << "required" if required?
|
32
|
-
opts[:class] << "autofocus" if autofocus?
|
33
|
-
opts[:class] = opts[:class].join(' ')
|
34
|
-
|
35
|
-
opts[:id] ||= wrapper_dom_id
|
36
|
-
|
17
|
+
opts = wrapper_html_options_raw
|
18
|
+
opts[:class] = wrapper_classes
|
19
|
+
opts[:id] ||= wrapper_dom_id
|
37
20
|
opts
|
38
21
|
end
|
39
22
|
|
23
|
+
def wrapper_html_options_raw
|
24
|
+
(options[:wrapper_html] || {}).dup
|
25
|
+
end
|
26
|
+
|
27
|
+
def wrapper_classes_raw
|
28
|
+
classes = wrapper_html_options_raw[:class] || []
|
29
|
+
return classes.dup if classes.is_a?(Array)
|
30
|
+
return [classes]
|
31
|
+
end
|
32
|
+
|
33
|
+
def wrapper_classes
|
34
|
+
classes = wrapper_classes_raw
|
35
|
+
classes << as
|
36
|
+
classes << "input"
|
37
|
+
classes << "error" if errors?
|
38
|
+
classes << "optional" if optional?
|
39
|
+
classes << "required" if required?
|
40
|
+
classes << "autofocus" if autofocus?
|
41
|
+
|
42
|
+
classes.join(' ')
|
43
|
+
end
|
44
|
+
|
40
45
|
def wrapper_dom_id
|
41
46
|
@wrapper_dom_id ||= "#{dom_id.to_s.gsub((association_primary_key || method).to_s, sanitized_method_name.to_s)}_input"
|
42
47
|
end
|
@@ -97,9 +97,32 @@ module Formtastic
|
|
97
97
|
end
|
98
98
|
|
99
99
|
def checked?
|
100
|
-
|
100
|
+
if defined? ActionView::Helpers::InstanceTag
|
101
|
+
object && ActionView::Helpers::InstanceTag.check_box_checked?(object.send(method), checked_value)
|
102
|
+
else
|
103
|
+
object && boolean_checked?(object.send(method), checked_value)
|
104
|
+
end
|
101
105
|
end
|
106
|
+
|
107
|
+
private
|
102
108
|
|
109
|
+
def boolean_checked?(value, checked_value)
|
110
|
+
case value
|
111
|
+
when TrueClass, FalseClass
|
112
|
+
value
|
113
|
+
when NilClass
|
114
|
+
false
|
115
|
+
when Integer
|
116
|
+
value != 0
|
117
|
+
when String
|
118
|
+
value == checked_value
|
119
|
+
when Array
|
120
|
+
value.include?(checked_value)
|
121
|
+
else
|
122
|
+
value.to_i != 0
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
103
126
|
end
|
104
127
|
end
|
105
128
|
end
|
@@ -1,34 +1,10 @@
|
|
1
1
|
module Formtastic
|
2
2
|
module Inputs
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
include Base
|
8
|
-
include Base::Timeish
|
9
|
-
|
10
|
-
# We don't want hour and minute fragments on a date input
|
11
|
-
def time_fragments
|
12
|
-
[]
|
3
|
+
class DateInput < DateSelectInput
|
4
|
+
def to_html
|
5
|
+
::ActiveSupport::Deprecation.warn("DateInput (:as => :date) has been renamed to DateSelectInput (:as => :date_select) and will be removed or changed in the next version of Formtastic, please update your forms.", caller(2))
|
6
|
+
super
|
13
7
|
end
|
14
|
-
|
15
|
-
def hidden_date_fragments
|
16
|
-
default_date_fragments - date_fragments
|
17
|
-
end
|
18
|
-
|
19
|
-
def hidden_fragments
|
20
|
-
hidden_date_fragments.map do |fragment|
|
21
|
-
template.hidden_field_tag(hidden_field_name(fragment), fragment_value(fragment), :id => fragment_id(fragment), :disabled => input_html_options[:disabled] )
|
22
|
-
end.join.html_safe
|
23
|
-
end
|
24
|
-
|
25
|
-
def fragment_value(fragment)
|
26
|
-
if fragment == :year
|
27
|
-
Time.now.year
|
28
|
-
else
|
29
|
-
'1'
|
30
|
-
end
|
31
|
-
end
|
32
8
|
end
|
33
9
|
end
|
34
|
-
end
|
10
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module Formtastic
|
2
|
+
module Inputs
|
3
|
+
|
4
|
+
# Outputs a simple `<label>` with a HTML5 `<input type="date">` wrapped in the standard
|
5
|
+
# `<li>` wrapper. This is an alternative to `:date_select` for `:date`, `:time`, `:datetime`
|
6
|
+
# database columns. You can use this input with `:as => :date_picker`.
|
7
|
+
#
|
8
|
+
# *Please note:* Formtastic only provides suitable markup for a date picker, but does not supply
|
9
|
+
# any additional CSS or Javascript to render calendar-style date pickers. Browsers that support
|
10
|
+
# this input type (such as Mobile Webkit and Opera on the desktop) will render a native widget.
|
11
|
+
# Browsers that don't will default to a plain text field`<input type="text">` and can be
|
12
|
+
# poly-filled with some Javascript and a UI library of your choice.
|
13
|
+
#
|
14
|
+
# @example Full form context and output
|
15
|
+
#
|
16
|
+
# <%= semantic_form_for(@post) do |f| %>
|
17
|
+
# <%= f.inputs do %>
|
18
|
+
# <%= f.input :publish_at, :as => :date_picker %>
|
19
|
+
# <% end %>
|
20
|
+
# <% end %>
|
21
|
+
#
|
22
|
+
# <form...>
|
23
|
+
# <fieldset>
|
24
|
+
# <ol>
|
25
|
+
# <li class="string">
|
26
|
+
# <label for="post_publish_at">First name</label>
|
27
|
+
# <input type="date" id="post_publish_at" name="post[publish_at]">
|
28
|
+
# </li>
|
29
|
+
# </ol>
|
30
|
+
# </fieldset>
|
31
|
+
# </form>
|
32
|
+
#
|
33
|
+
# @example Setting the size (defaults to 10 for YYYY-MM-DD)
|
34
|
+
# <%= f.input :publish_at, :as => :date_picker, :size => 20 %>
|
35
|
+
# <%= f.input :publish_at, :as => :date_picker, :input_html => { :size => 20 } %>
|
36
|
+
#
|
37
|
+
# @example Setting the maxlength (defaults to 10 for YYYY-MM-DD)
|
38
|
+
# <%= f.input :publish_at, :as => :date_picker, :maxlength => 20 %>
|
39
|
+
# <%= f.input :publish_at, :as => :date_picker, :input_html => { :maxlength => 20 } %>
|
40
|
+
#
|
41
|
+
# @example Setting the value (defaults to YYYY-MM-DD for Date and Time objects, otherwise renders string)
|
42
|
+
# <%= f.input :publish_at, :as => :date_picker, :input_html => { :value => "1970-01-01" } %>
|
43
|
+
#
|
44
|
+
# @example Setting the step attribute (defaults to 1)
|
45
|
+
# <%= f.input :publish_at, :as => :date_picker, :step => 7 %>
|
46
|
+
# <%= f.input :publish_at, :as => :date_picker, :input_html => { :step => 7 } %>
|
47
|
+
#
|
48
|
+
# @example Setting the step attribute with a macro
|
49
|
+
# <%= f.input :publish_at, :as => :date_picker, :step => :day %>
|
50
|
+
# <%= f.input :publish_at, :as => :date_picker, :step => :week %>
|
51
|
+
# <%= f.input :publish_at, :as => :date_picker, :step => :seven_days %>
|
52
|
+
# <%= f.input :publish_at, :as => :date_picker, :step => :fortnight %>
|
53
|
+
# <%= f.input :publish_at, :as => :date_picker, :step => :two_weeks %>
|
54
|
+
# <%= f.input :publish_at, :as => :date_picker, :step => :four_weeks %>
|
55
|
+
# <%= f.input :publish_at, :as => :date_picker, :step => :thirty_days %>
|
56
|
+
#
|
57
|
+
# @example Setting the min attribute
|
58
|
+
# <%= f.input :publish_at, :as => :date_picker, :min => "2012-01-01" %>
|
59
|
+
# <%= f.input :publish_at, :as => :date_picker, :input_html => { :min => "2012-01-01" } %>
|
60
|
+
#
|
61
|
+
# @example Setting the max attribute
|
62
|
+
# <%= f.input :publish_at, :as => :date_picker, :max => "2012-12-31" %>
|
63
|
+
# <%= f.input :publish_at, :as => :date_picker, :input_html => { :max => "2012-12-31" } %>
|
64
|
+
#
|
65
|
+
# @example Setting the placeholder attribute
|
66
|
+
# <%= f.input :publish_at, :as => :date_picker, :placeholder => 20 %>
|
67
|
+
# <%= f.input :publish_at, :as => :date_picker, :input_html => { :placeholder => "YYYY-MM-DD" } %>
|
68
|
+
#
|
69
|
+
# @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
|
70
|
+
class DatePickerInput
|
71
|
+
include Base
|
72
|
+
include Base::Stringish
|
73
|
+
include Base::DatetimePickerish
|
74
|
+
|
75
|
+
def html_input_type
|
76
|
+
"date"
|
77
|
+
end
|
78
|
+
|
79
|
+
def default_size
|
80
|
+
10
|
81
|
+
end
|
82
|
+
|
83
|
+
def value
|
84
|
+
return options[:input_html][:value] if options[:input_html] && options[:input_html].key?(:value)
|
85
|
+
val = object.send(method)
|
86
|
+
return Date.new(val.year, val.month, val.day).to_s if val.is_a?(Time)
|
87
|
+
return val if val.nil?
|
88
|
+
val.to_s
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Formtastic
|
2
|
+
module Inputs
|
3
|
+
# Outputs a series of select boxes for the fragments that make up a date (year, month, day).
|
4
|
+
#
|
5
|
+
# @see Formtastic::Inputs::Base::Timeish Timeish module for documentation of date, time and datetime input options.
|
6
|
+
class DateSelectInput
|
7
|
+
include Base
|
8
|
+
include Base::Timeish
|
9
|
+
|
10
|
+
# We don't want hour and minute fragments on a date input
|
11
|
+
def time_fragments
|
12
|
+
[]
|
13
|
+
end
|
14
|
+
|
15
|
+
def hidden_date_fragments
|
16
|
+
default_date_fragments - date_fragments
|
17
|
+
end
|
18
|
+
|
19
|
+
def hidden_fragments
|
20
|
+
hidden_date_fragments.map do |fragment|
|
21
|
+
template.hidden_field_tag(hidden_field_name(fragment), fragment_value(fragment), :id => fragment_id(fragment), :disabled => input_html_options[:disabled] )
|
22
|
+
end.join.html_safe
|
23
|
+
end
|
24
|
+
|
25
|
+
def fragment_value(fragment)
|
26
|
+
if fragment == :year
|
27
|
+
Time.now.year
|
28
|
+
else
|
29
|
+
'1'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,12 +1,10 @@
|
|
1
1
|
module Formtastic
|
2
2
|
module Inputs
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
include Base
|
9
|
-
include Base::Timeish
|
3
|
+
class DatetimeInput < DatetimeSelectInput
|
4
|
+
def to_html
|
5
|
+
::ActiveSupport::Deprecation.warn("DatetimeInput (:as => :datetime) has been renamed to DatetimeSelectInput (:as => :datetime_select) and will be removed or changed in the next version of Formtastic, please update your forms.", caller(2))
|
6
|
+
super
|
7
|
+
end
|
10
8
|
end
|
11
9
|
end
|
12
|
-
end
|
10
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module Formtastic
|
2
|
+
module Inputs
|
3
|
+
|
4
|
+
# Outputs a simple `<label>` with a HTML5 `<input type="datetime-local">` (or
|
5
|
+
# `<input type="datetime">`) wrapped in the standard `<li>` wrapper. This is an alternative to
|
6
|
+
# `:date_select` for `:date`, `:time`, `:datetime` database columns. You can use this input with
|
7
|
+
# `:as => :datetime_picker`.
|
8
|
+
#
|
9
|
+
# *Please note:* Formtastic only provides suitable markup for a date picker, but does not supply
|
10
|
+
# any additional CSS or Javascript to render calendar-style date pickers. Browsers that support
|
11
|
+
# this input type (such as Mobile Webkit and Opera on the desktop) will render a native widget.
|
12
|
+
# Browsers that don't will default to a plain text field`<input type="text">` and can be
|
13
|
+
# poly-filled with some Javascript and a UI library of your choice.
|
14
|
+
#
|
15
|
+
# @example Full form context and output
|
16
|
+
#
|
17
|
+
# <%= semantic_form_for(@post) do |f| %>
|
18
|
+
# <%= f.inputs do %>
|
19
|
+
# <%= f.input :publish_at, :as => :datetime_picker %>
|
20
|
+
# <% end %>
|
21
|
+
# <% end %>
|
22
|
+
#
|
23
|
+
# <form...>
|
24
|
+
# <fieldset>
|
25
|
+
# <ol>
|
26
|
+
# <li class="string">
|
27
|
+
# <label for="post_publish_at">First name</label>
|
28
|
+
# <input type="date" id="post_publish_at" name="post[publish_at]">
|
29
|
+
# </li>
|
30
|
+
# </ol>
|
31
|
+
# </fieldset>
|
32
|
+
# </form>
|
33
|
+
#
|
34
|
+
# @example Setting the size (defaults to 16 for YYYY-MM-DD HH:MM)
|
35
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :size => 20 %>
|
36
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :input_html => { :size => 20 } %>
|
37
|
+
#
|
38
|
+
# @example Setting the maxlength (defaults to 16 for YYYY-MM-DD HH:MM)
|
39
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :maxlength => 20 %>
|
40
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :input_html => { :maxlength => 20 } %>
|
41
|
+
#
|
42
|
+
# @example Setting the value (defaults to YYYY-MM-DD HH:MM for Date and Time objects, otherwise renders string)
|
43
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :input_html => { :value => "1970-01-01 00:00" } %>
|
44
|
+
#
|
45
|
+
# @example Setting the step attribute (defaults to 1)
|
46
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :step => 60 %>
|
47
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :input_html => { :step => 60 } %>
|
48
|
+
#
|
49
|
+
# @example Setting the step attribute with a macro
|
50
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :step => :second %>
|
51
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :step => :minute %>
|
52
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :step => :quarter_hour %>
|
53
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :step => :fifteen_minutes %>
|
54
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :step => :half_hour %>
|
55
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :step => :thirty_minutes %>
|
56
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :step => :hour %>
|
57
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :step => :sixty_minutes %>
|
58
|
+
#
|
59
|
+
# @example Setting the min attribute
|
60
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :min => "2012-01-01 09:00" %>
|
61
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :input_html => { :min => "2012-01-01 09:00" } %>
|
62
|
+
#
|
63
|
+
# @example Setting the max attribute
|
64
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :max => "2012-12-31 16:00" %>
|
65
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :input_html => { :max => "2012-12-31 16:00" } %>
|
66
|
+
#
|
67
|
+
# @example Setting the placeholder attribute
|
68
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :placeholder => "YYYY-MM-DD HH:MM" %>
|
69
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :input_html => { :placeholder => "YYYY-MM-DD HH:MM" } %>
|
70
|
+
#
|
71
|
+
# @example Using `datetime` (UTC) or `datetime-local` with `:local` (defaults to true, `datetime-local` input)
|
72
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :local => false %>
|
73
|
+
#
|
74
|
+
# @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
|
75
|
+
class DatetimePickerInput
|
76
|
+
include Base
|
77
|
+
include Base::Stringish
|
78
|
+
include Base::DatetimePickerish
|
79
|
+
|
80
|
+
def html_input_type
|
81
|
+
options[:local] = true unless options.key?(:local)
|
82
|
+
options[:local] ? "datetime-local" : "datetime"
|
83
|
+
end
|
84
|
+
|
85
|
+
def default_size
|
86
|
+
16
|
87
|
+
end
|
88
|
+
|
89
|
+
def value
|
90
|
+
return options[:input_html][:value] if options[:input_html] && options[:input_html].key?(:value)
|
91
|
+
val = object.send(method)
|
92
|
+
return val.strftime("%Y-%m-%d %H:%M") if val.is_a?(Time)
|
93
|
+
return "#{val.year}-#{val.month}-#{val.day} 00:00" if val.is_a?(Date)
|
94
|
+
return val if val.nil?
|
95
|
+
val.to_s
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Formtastic
|
2
|
+
module Inputs
|
3
|
+
|
4
|
+
# Outputs a series of select boxes for the fragments that make up a date and time (year, month, day, hour, minute, second).
|
5
|
+
#
|
6
|
+
# @see Formtastic::Inputs::Base::Timeish Timeish module for documentation of date, time and datetime input options.
|
7
|
+
class DatetimeSelectInput
|
8
|
+
include Base
|
9
|
+
include Base::Timeish
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -34,7 +34,7 @@ module Formtastic
|
|
34
34
|
# Override to include :value set directly from options hash. The :value set in :input_html
|
35
35
|
# hash will be preferred over :value set directly in the options.
|
36
36
|
#
|
37
|
-
# @
|
37
|
+
# @deprecated :value option
|
38
38
|
def input_html_options
|
39
39
|
options.slice(:value).merge(super).merge(:required => nil).merge(:autofocus => nil)
|
40
40
|
end
|
@@ -20,7 +20,7 @@ module Formtastic
|
|
20
20
|
#
|
21
21
|
# * a `:string` input (where you want to force the user to choose from a few specific strings rather than entering anything)
|
22
22
|
# * a `:boolean` checkbox input (where the user could choose yes or no, rather than checking a box)
|
23
|
-
# * a `:
|
23
|
+
# * a `:date_select`, `:time_select` or `:datetime_select` input (where the user could choose from a small set of pre-determined dates)
|
24
24
|
# * a `:number` input (where the user could choose from a small set of pre-defined numbers)
|
25
25
|
# * a `:time_zone` input (where you want to provide your own small set of choices instead of relying on Rails)
|
26
26
|
# * a `:country` input (where you want to provide a small set of choices, no need for a plugin really)
|
@@ -17,7 +17,7 @@ module Formtastic
|
|
17
17
|
#
|
18
18
|
# * a `:string` input (where you want to force the user to choose from a few specific strings rather than entering anything)
|
19
19
|
# * a `:boolean` checkbox input (where the user could choose yes or no, rather than checking a box)
|
20
|
-
# * a `:
|
20
|
+
# * a `:date_select`, `:time_select` or `:datetime_select` input (where the user could choose from pre-selected dates)
|
21
21
|
# * a `:number` input (where the user could choose from a set of pre-defined numbers)
|
22
22
|
# * a `:time_zone` input (where you want to provide your own set of choices instead of relying on Rails)
|
23
23
|
# * a `:country` input (no need for a plugin really)
|
@@ -132,9 +132,6 @@ module Formtastic
|
|
132
132
|
# <%= f.input :author, :as => :select, :prompt => "Please select an author" %>
|
133
133
|
#
|
134
134
|
#
|
135
|
-
# @example Group options an `<optgroup>` with the `:group_by` and `:group_label` options (`belongs_to` associations only)
|
136
|
-
# <%= f.input :author, :as => :select, :group_by => :continent %>
|
137
|
-
#
|
138
135
|
# @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
|
139
136
|
# @see Formtastic::Inputs::CheckBoxesInput CheckBoxesInput as an alternative for `has_many` and `has_and_belongs_to_many` associations
|
140
137
|
# @see Formtastic::Inputs::RadioInput RadioInput as an alternative for `belongs_to` associations
|
@@ -195,7 +192,7 @@ module Formtastic
|
|
195
192
|
end
|
196
193
|
|
197
194
|
def input_html_options
|
198
|
-
extra_input_html_options.merge(super)
|
195
|
+
extra_input_html_options.merge(super.reject {|k,v| k==:name && v.nil?} )
|
199
196
|
end
|
200
197
|
|
201
198
|
def extra_input_html_options
|
@@ -1,34 +1,10 @@
|
|
1
1
|
module Formtastic
|
2
2
|
module Inputs
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
#
|
8
|
-
# @see Formtastic::Inputs::Base::Timeish Timeish module for documentation of date, time and datetime input options.
|
9
|
-
class TimeInput
|
10
|
-
include Base
|
11
|
-
include Base::Timeish
|
12
|
-
|
13
|
-
# we don't want year / month / day fragments if :ignore_date => true
|
14
|
-
def fragments
|
15
|
-
time_fragments
|
3
|
+
class TimeInput < TimeSelectInput
|
4
|
+
def to_html
|
5
|
+
::ActiveSupport::Deprecation.warn("TimeInput (:as => :time) has been renamed to TimeSelectInput (:as => :time_select) and will be removed or changed in the next version of Formtastic, please update your forms.", caller(2))
|
6
|
+
super
|
16
7
|
end
|
17
|
-
|
18
|
-
def fragment_value(fragment)
|
19
|
-
value ? value.send(fragment) : ""
|
20
|
-
end
|
21
|
-
|
22
|
-
def hidden_fragments
|
23
|
-
if !options[:ignore_date]
|
24
|
-
date_fragments.map do |fragment|
|
25
|
-
template.hidden_field_tag(hidden_field_name(fragment), fragment_value(fragment), :id => fragment_id(fragment), :disabled => input_html_options[:disabled] )
|
26
|
-
end.join.html_safe
|
27
|
-
else
|
28
|
-
super
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
8
|
end
|
33
9
|
end
|
34
10
|
end
|