formtastic 1.2.4 → 3.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +46 -0
- data/.yardopts +1 -0
- data/Appraisals +43 -0
- data/CHANGELOG +54 -0
- data/DEPRECATIONS +52 -0
- data/Gemfile +3 -0
- data/README.md +629 -0
- data/RELEASE_PROCESS +6 -0
- data/Rakefile +35 -0
- data/app/assets/stylesheets/formtastic.css +289 -0
- data/app/assets/stylesheets/formtastic_ie6.css +33 -0
- data/app/assets/stylesheets/formtastic_ie7.css +23 -0
- data/formtastic.gemspec +42 -0
- data/gemfiles/rails_3.2.gemfile +9 -0
- data/gemfiles/rails_4.0.4.gemfile +8 -0
- data/gemfiles/rails_4.1.gemfile +8 -0
- data/gemfiles/rails_4.2.gemfile +8 -0
- data/gemfiles/rails_4.gemfile +8 -0
- data/gemfiles/rails_5.0.gemfile +8 -0
- data/gemfiles/rails_edge.gemfile +15 -0
- data/lib/formtastic.rb +40 -1945
- data/lib/formtastic/action_class_finder.rb +18 -0
- data/lib/formtastic/actions.rb +11 -0
- data/lib/formtastic/actions/base.rb +156 -0
- data/lib/formtastic/actions/button_action.rb +67 -0
- data/lib/formtastic/actions/buttonish.rb +17 -0
- data/lib/formtastic/actions/input_action.rb +70 -0
- data/lib/formtastic/actions/link_action.rb +88 -0
- data/lib/formtastic/deprecation.rb +42 -0
- data/lib/formtastic/engine.rb +11 -0
- data/lib/formtastic/form_builder.rb +124 -0
- data/lib/formtastic/helpers.rb +16 -0
- data/lib/formtastic/helpers/action_helper.rb +162 -0
- data/lib/formtastic/helpers/actions_helper.rb +168 -0
- data/lib/formtastic/helpers/enum.rb +13 -0
- data/lib/formtastic/helpers/errors_helper.rb +81 -0
- data/lib/formtastic/helpers/fieldset_wrapper.rb +80 -0
- data/lib/formtastic/helpers/file_column_detection.rb +16 -0
- data/lib/formtastic/helpers/form_helper.rb +203 -0
- data/lib/formtastic/helpers/input_helper.rb +407 -0
- data/lib/formtastic/helpers/inputs_helper.rb +411 -0
- data/lib/formtastic/helpers/reflection.rb +37 -0
- data/lib/formtastic/html_attributes.rb +32 -0
- data/lib/formtastic/i18n.rb +4 -2
- data/lib/formtastic/input_class_finder.rb +18 -0
- data/lib/formtastic/inputs.rb +39 -0
- data/lib/formtastic/inputs/base.rb +76 -0
- data/lib/formtastic/inputs/base/associations.rb +31 -0
- data/lib/formtastic/inputs/base/choices.rb +108 -0
- data/lib/formtastic/inputs/base/collections.rb +159 -0
- data/lib/formtastic/inputs/base/database.rb +22 -0
- data/lib/formtastic/inputs/base/datetime_pickerish.rb +85 -0
- data/lib/formtastic/inputs/base/errors.rb +58 -0
- data/lib/formtastic/inputs/base/fileish.rb +23 -0
- data/lib/formtastic/inputs/base/hints.rb +31 -0
- data/lib/formtastic/inputs/base/html.rb +53 -0
- data/lib/formtastic/inputs/base/labelling.rb +52 -0
- data/lib/formtastic/inputs/base/naming.rb +42 -0
- data/lib/formtastic/inputs/base/numeric.rb +50 -0
- data/lib/formtastic/inputs/base/options.rb +17 -0
- data/lib/formtastic/inputs/base/placeholder.rb +17 -0
- data/lib/formtastic/inputs/base/stringish.rb +38 -0
- data/lib/formtastic/inputs/base/timeish.rb +241 -0
- data/lib/formtastic/inputs/base/validations.rb +215 -0
- data/lib/formtastic/inputs/base/wrapping.rb +50 -0
- data/lib/formtastic/inputs/boolean_input.rb +118 -0
- data/lib/formtastic/inputs/check_boxes_input.rb +197 -0
- data/lib/formtastic/inputs/color_input.rb +42 -0
- data/lib/formtastic/inputs/country_input.rb +86 -0
- data/lib/formtastic/inputs/datalist_input.rb +41 -0
- 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_picker_input.rb +103 -0
- data/lib/formtastic/inputs/datetime_select_input.rb +12 -0
- data/lib/formtastic/inputs/email_input.rb +41 -0
- data/lib/formtastic/inputs/file_input.rb +42 -0
- data/lib/formtastic/inputs/hidden_input.rb +62 -0
- data/lib/formtastic/inputs/number_input.rb +88 -0
- data/lib/formtastic/inputs/password_input.rb +41 -0
- data/lib/formtastic/inputs/phone_input.rb +42 -0
- data/lib/formtastic/inputs/radio_input.rb +163 -0
- data/lib/formtastic/inputs/range_input.rb +95 -0
- data/lib/formtastic/inputs/search_input.rb +41 -0
- data/lib/formtastic/inputs/select_input.rb +235 -0
- data/lib/formtastic/inputs/string_input.rb +36 -0
- data/lib/formtastic/inputs/text_input.rb +48 -0
- data/lib/formtastic/inputs/time_picker_input.rb +99 -0
- data/lib/formtastic/inputs/time_select_input.rb +38 -0
- data/lib/formtastic/inputs/time_zone_input.rb +58 -0
- data/lib/formtastic/inputs/url_input.rb +41 -0
- data/lib/formtastic/localized_string.rb +17 -0
- data/lib/formtastic/localizer.rb +152 -0
- data/lib/formtastic/namespaced_class_finder.rb +99 -0
- data/lib/formtastic/util.rb +35 -16
- data/lib/formtastic/version.rb +3 -0
- data/lib/generators/formtastic/form/form_generator.rb +64 -37
- data/lib/generators/formtastic/input/input_generator.rb +46 -0
- data/lib/generators/formtastic/install/install_generator.rb +13 -5
- data/lib/generators/templates/_form.html.erb +10 -4
- data/lib/generators/templates/_form.html.haml +8 -4
- data/lib/generators/templates/_form.html.slim +8 -0
- data/lib/generators/templates/formtastic.rb +77 -44
- data/lib/generators/templates/input.rb +19 -0
- data/lib/locale/en.yml +3 -0
- data/sample/basic_inputs.html +224 -0
- data/sample/config.ru +69 -0
- data/sample/index.html +14 -0
- data/spec/action_class_finder_spec.rb +12 -0
- data/spec/actions/button_action_spec.rb +63 -0
- data/spec/actions/generic_action_spec.rb +521 -0
- data/spec/actions/input_action_spec.rb +59 -0
- data/spec/actions/link_action_spec.rb +92 -0
- data/spec/builder/custom_builder_spec.rb +116 -0
- data/spec/builder/error_proc_spec.rb +27 -0
- data/spec/builder/semantic_fields_for_spec.rb +142 -0
- data/spec/fast_spec_helper.rb +12 -0
- data/spec/generators/formtastic/form/form_generator_spec.rb +131 -0
- data/spec/generators/formtastic/input/input_generator_spec.rb +124 -0
- data/spec/generators/formtastic/install/install_generator_spec.rb +47 -0
- data/spec/helpers/action_helper_spec.rb +19 -0
- data/spec/helpers/actions_helper_spec.rb +143 -0
- data/spec/helpers/form_helper_spec.rb +218 -0
- data/spec/helpers/input_helper_spec.rb +6 -0
- data/spec/helpers/inputs_helper_spec.rb +655 -0
- data/spec/helpers/namespaced_action_helper_spec.rb +43 -0
- data/spec/helpers/namespaced_input_helper_spec.rb +36 -0
- data/spec/helpers/reflection_helper_spec.rb +32 -0
- data/spec/helpers/semantic_errors_helper_spec.rb +112 -0
- data/spec/i18n_spec.rb +210 -0
- data/spec/input_class_finder_spec.rb +10 -0
- data/spec/inputs/base/collections_spec.rb +76 -0
- data/spec/inputs/base/validations_spec.rb +342 -0
- data/spec/inputs/boolean_input_spec.rb +254 -0
- data/spec/inputs/check_boxes_input_spec.rb +546 -0
- data/spec/inputs/color_input_spec.rb +97 -0
- data/spec/inputs/country_input_spec.rb +133 -0
- data/spec/inputs/custom_input_spec.rb +55 -0
- data/spec/inputs/datalist_input_spec.rb +61 -0
- data/spec/inputs/date_picker_input_spec.rb +449 -0
- data/spec/inputs/date_select_input_spec.rb +235 -0
- data/spec/inputs/datetime_picker_input_spec.rb +490 -0
- data/spec/inputs/datetime_select_input_spec.rb +193 -0
- data/spec/inputs/email_input_spec.rb +85 -0
- data/spec/inputs/file_input_spec.rb +89 -0
- data/spec/inputs/hidden_input_spec.rb +135 -0
- data/spec/inputs/include_blank_spec.rb +78 -0
- data/spec/inputs/label_spec.rb +149 -0
- data/spec/inputs/number_input_spec.rb +815 -0
- data/spec/inputs/password_input_spec.rb +99 -0
- data/spec/inputs/phone_input_spec.rb +85 -0
- data/spec/inputs/placeholder_spec.rb +71 -0
- data/spec/inputs/radio_input_spec.rb +328 -0
- data/spec/inputs/range_input_spec.rb +505 -0
- data/spec/inputs/readonly_spec.rb +50 -0
- data/spec/inputs/search_input_spec.rb +84 -0
- data/spec/inputs/select_input_spec.rb +615 -0
- data/spec/inputs/string_input_spec.rb +260 -0
- data/spec/inputs/text_input_spec.rb +187 -0
- data/spec/inputs/time_picker_input_spec.rb +455 -0
- data/spec/inputs/time_select_input_spec.rb +248 -0
- data/spec/inputs/time_zone_input_spec.rb +143 -0
- data/spec/inputs/url_input_spec.rb +85 -0
- data/spec/inputs/with_options_spec.rb +43 -0
- data/spec/localizer_spec.rb +130 -0
- data/spec/namespaced_class_finder_spec.rb +79 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +525 -0
- data/spec/support/custom_macros.rb +564 -0
- data/spec/support/deprecation.rb +6 -0
- data/spec/support/shared_examples.rb +1313 -0
- data/spec/support/specialized_class_finder_shared_example.rb +27 -0
- data/spec/support/test_environment.rb +31 -0
- data/spec/util_spec.rb +66 -0
- metadata +434 -161
- data/README.textile +0 -682
- data/generators/form/USAGE +0 -16
- data/generators/form/form_generator.rb +0 -111
- data/generators/formtastic/formtastic_generator.rb +0 -26
- data/init.rb +0 -5
- data/lib/formtastic/layout_helper.rb +0 -12
- data/lib/formtastic/railtie.rb +0 -14
- data/lib/generators/templates/formtastic.css +0 -145
- data/lib/generators/templates/formtastic_changes.css +0 -14
- data/lib/generators/templates/rails2/_form.html.erb +0 -5
- data/lib/generators/templates/rails2/_form.html.haml +0 -4
- data/rails/init.rb +0 -2
@@ -0,0 +1,41 @@
|
|
1
|
+
module Formtastic
|
2
|
+
module Inputs
|
3
|
+
# Outputs a label and a text field, along with a datalist tag
|
4
|
+
# datalist tag provides a list of options which drives a simple autocomplete
|
5
|
+
# on the text field. This is a HTML5 feature, more info can be found at
|
6
|
+
# {https://developer.mozilla.org/en/docs/Web/HTML/Element/datalist <datalist> at MDN}
|
7
|
+
# This input accepts a :collection option which takes data in all the usual formats accepted by
|
8
|
+
# {http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/options_for_select options_for_select}
|
9
|
+
#
|
10
|
+
# @example Input is used as follows
|
11
|
+
# f.input :fav_book, :as => :datalist, :collection => Book.pluck(:name)
|
12
|
+
#
|
13
|
+
class DatalistInput
|
14
|
+
include Base
|
15
|
+
include Base::Stringish
|
16
|
+
include Base::Collections
|
17
|
+
|
18
|
+
def to_html
|
19
|
+
@name = input_html_options[:id].gsub(/_id$/, "")
|
20
|
+
input_wrapping do
|
21
|
+
label_html <<
|
22
|
+
builder.text_field(method, input_html_options) << # standard input
|
23
|
+
data_list_html # append new datalist element
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def input_html_options
|
28
|
+
super.merge(:list => html_id_of_datalist)
|
29
|
+
end
|
30
|
+
|
31
|
+
def html_id_of_datalist
|
32
|
+
"#{@name}_datalist"
|
33
|
+
end
|
34
|
+
|
35
|
+
def data_list_html
|
36
|
+
html = builder.template.options_for_select(collection)
|
37
|
+
builder.template.content_tag(:datalist,html, { :id => html_id_of_datalist }, false)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
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
|
@@ -0,0 +1,103 @@
|
|
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 `type=datetime-local` with `:local` option (this is the default, and recommended for browser support on iOS7 and Chrome)
|
72
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :local => true %>
|
73
|
+
#
|
74
|
+
# @example Using `type=datetime` with `:local` option (not recommended)
|
75
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :local => false %>
|
76
|
+
#
|
77
|
+
# @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
|
78
|
+
class DatetimePickerInput
|
79
|
+
include Base
|
80
|
+
include Base::Stringish
|
81
|
+
include Base::DatetimePickerish
|
82
|
+
|
83
|
+
def html_input_type
|
84
|
+
options[:local] = true unless options.key?(:local)
|
85
|
+
options[:local] ? "datetime-local" : "datetime"
|
86
|
+
end
|
87
|
+
|
88
|
+
def default_size
|
89
|
+
16
|
90
|
+
end
|
91
|
+
|
92
|
+
def value
|
93
|
+
return options[:input_html][:value] if options[:input_html] && options[:input_html].key?(:value)
|
94
|
+
val = object.send(method)
|
95
|
+
return val.strftime("%Y-%m-%dT%H:%M:%S") if val.is_a?(Time)
|
96
|
+
return "#{val.year}-#{val.month}-#{val.day}T00:00:00" if val.is_a?(Date)
|
97
|
+
return val if val.nil?
|
98
|
+
val.to_s
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
103
|
+
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
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Formtastic
|
2
|
+
module Inputs
|
3
|
+
|
4
|
+
# Outputs a simple `<label>` with a HTML5 `<input type="email">` wrapped in the standard
|
5
|
+
# `<li>` wrapper. This is the default input choice for attributes with a name matching
|
6
|
+
# `/email/`, but can be applied to any text-like input with `:as => :email`.
|
7
|
+
#
|
8
|
+
# @example Full form context and output
|
9
|
+
#
|
10
|
+
# <%= semantic_form_for(@user) do |f| %>
|
11
|
+
# <%= f.inputs do %>
|
12
|
+
# <%= f.input :email_address, :as => :email %>
|
13
|
+
# <% end %>
|
14
|
+
# <% end %>
|
15
|
+
#
|
16
|
+
# <form...>
|
17
|
+
# <fieldset>
|
18
|
+
# <ol>
|
19
|
+
# <li class="email">
|
20
|
+
# <label for="user_email_address">Email address</label>
|
21
|
+
# <input type="email" id="user_email_address" name="user[email_address]">
|
22
|
+
# </li>
|
23
|
+
# </ol>
|
24
|
+
# </fieldset>
|
25
|
+
# </form>
|
26
|
+
#
|
27
|
+
# @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
|
28
|
+
class EmailInput
|
29
|
+
include Base
|
30
|
+
include Base::Stringish
|
31
|
+
include Base::Placeholder
|
32
|
+
|
33
|
+
def to_html
|
34
|
+
input_wrapping do
|
35
|
+
label_html <<
|
36
|
+
builder.email_field(method, input_html_options)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Formtastic
|
2
|
+
module Inputs
|
3
|
+
|
4
|
+
# Outputs a simple `<label>` with a `<input type="file">` wrapped in the standard
|
5
|
+
# `<li>` wrapper. This is the default input choice for objects with attributes that appear
|
6
|
+
# to be for file uploads, by detecting some common method names used by popular file upload
|
7
|
+
# libraries such as Paperclip and CarrierWave. You can add to or alter these method names
|
8
|
+
# through the `file_methods` config, but can be applied to any input with `:as => :file`.
|
9
|
+
#
|
10
|
+
# Don't forget to set the multipart attribute in your `<form>` tag!
|
11
|
+
#
|
12
|
+
# @example Full form context and output
|
13
|
+
#
|
14
|
+
# <%= semantic_form_for(@user, :html => { :multipart => true }) do |f| %>
|
15
|
+
# <%= f.inputs do %>
|
16
|
+
# <%= f.input :avatar, :as => :file %>
|
17
|
+
# <% end %>
|
18
|
+
# <% end %>
|
19
|
+
#
|
20
|
+
# <form...>
|
21
|
+
# <fieldset>
|
22
|
+
# <ol>
|
23
|
+
# <li class="file">
|
24
|
+
# <label for="user_avatar">Avatar</label>
|
25
|
+
# <input type="file" id="user_avatar" name="user[avatar]">
|
26
|
+
# </li>
|
27
|
+
# </ol>
|
28
|
+
# </fieldset>
|
29
|
+
# </form>
|
30
|
+
#
|
31
|
+
# @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
|
32
|
+
class FileInput
|
33
|
+
include Base
|
34
|
+
def to_html
|
35
|
+
input_wrapping do
|
36
|
+
label_html <<
|
37
|
+
builder.file_field(method, input_html_options)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Formtastic
|
2
|
+
module Inputs
|
3
|
+
|
4
|
+
# Outputs a simple `<input type="hidden">` wrapped in the standard `<li>` wrapper. This is
|
5
|
+
# provided for situations where a hidden field needs to be rendered in the flow of a form with
|
6
|
+
# many inputs that form an `<ol>`. Wrapping the hidden input inside the `<li>` maintains the
|
7
|
+
# HTML validity. The `<li>` is marked with a `class` of `hidden` so that stylesheet authors can
|
8
|
+
# hide these list items with CSS (formtastic.css does this out of the box).
|
9
|
+
#
|
10
|
+
# @example Full form context, output and CSS
|
11
|
+
#
|
12
|
+
# <%= semantic_form_for(@something) do |f| %>
|
13
|
+
# <%= f.inputs do %>
|
14
|
+
# <%= f.input :secret, :as => :hidden %>
|
15
|
+
# <% end %>
|
16
|
+
# <% end %>
|
17
|
+
#
|
18
|
+
# <form...>
|
19
|
+
# <fieldset>
|
20
|
+
# <ol>
|
21
|
+
# <li class="hidden">
|
22
|
+
# <input type="hidden" id="something_secret" name="something[secret]">
|
23
|
+
# </li>
|
24
|
+
# </ol>
|
25
|
+
# </fieldset>
|
26
|
+
# </form>
|
27
|
+
#
|
28
|
+
# form.formtastic li.hidden { display:none; }
|
29
|
+
#
|
30
|
+
# @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
|
31
|
+
class HiddenInput
|
32
|
+
include Base
|
33
|
+
|
34
|
+
def input_html_options
|
35
|
+
super.merge(:required => nil).merge(:autofocus => nil)
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_html
|
39
|
+
input_wrapping do
|
40
|
+
builder.hidden_field(method, input_html_options)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def error_html
|
45
|
+
""
|
46
|
+
end
|
47
|
+
|
48
|
+
def errors?
|
49
|
+
false
|
50
|
+
end
|
51
|
+
|
52
|
+
def hint_html
|
53
|
+
""
|
54
|
+
end
|
55
|
+
|
56
|
+
def hint?
|
57
|
+
false
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Formtastic
|
2
|
+
module Inputs
|
3
|
+
|
4
|
+
# Outputs a simple `<label>` with a HTML5 `<input type="number">` wrapped in the standard
|
5
|
+
# `<li>` wrapper. This is the default input choice for all database columns of the type `:float`
|
6
|
+
# and `:decimal`, as well as `:integer` columns that aren't used for `belongs_to` associations,
|
7
|
+
# but can be applied to any text-like input with `:as => :number`.
|
8
|
+
#
|
9
|
+
# Sensible default values for the `min`, `max` and `step` attributes are found by reflecting on
|
10
|
+
# the model's validations (when provided). An `IndeterminableMinimumAttributeError` exception
|
11
|
+
# will be raised when the following conditions are all true:
|
12
|
+
#
|
13
|
+
# * you haven't specified a `:min` or `:max` for the input
|
14
|
+
# * the model's database column type is a `:float` or `:decimal`
|
15
|
+
# * the validation uses `:less_than` or `:greater_than`
|
16
|
+
#
|
17
|
+
# The solution is to either:
|
18
|
+
#
|
19
|
+
# * manually specify the `:min` or `:max` for the input
|
20
|
+
# * change the database column type to an `:integer` (if appropriate)
|
21
|
+
# * change the validations to use `:less_than_or_equal_to` or `:greater_than_or_equal_to`
|
22
|
+
#
|
23
|
+
# @example Full form context and output
|
24
|
+
#
|
25
|
+
# <%= semantic_form_for(@user) do |f| %>
|
26
|
+
# <%= f.inputs do %>
|
27
|
+
# <%= f.input :shoe_size, :as => :number %>
|
28
|
+
# <% end %>
|
29
|
+
# <% end %>
|
30
|
+
#
|
31
|
+
# <form...>
|
32
|
+
# <fieldset>
|
33
|
+
# <ol>
|
34
|
+
# <li class="numeric">
|
35
|
+
# <label for="user_shoe_size">Shoe size</label>
|
36
|
+
# <input type="number" id="user_shoe_size" name="user[shoe_size]">
|
37
|
+
# </li>
|
38
|
+
# </ol>
|
39
|
+
# </fieldset>
|
40
|
+
# </form>
|
41
|
+
#
|
42
|
+
# @example Default HTML5 min/max/step attributes are detected from the numericality validations
|
43
|
+
#
|
44
|
+
# class Person < ActiveRecord::Base
|
45
|
+
# validates_numericality_of :age,
|
46
|
+
# :less_than_or_equal_to => 100,
|
47
|
+
# :greater_than_or_equal_to => 18,
|
48
|
+
# :only_integer => true
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# <%= f.input :age, :as => :number %>
|
52
|
+
#
|
53
|
+
# <li class="numeric">
|
54
|
+
# <label for="persom_age">Age</label>
|
55
|
+
# <input type="number" id="person_age" name="person[age]" min="18" max="100" step="1">
|
56
|
+
# </li>
|
57
|
+
#
|
58
|
+
# @example Pass attributes down to the `<input>` tag with :input_html
|
59
|
+
# <%= f.input :shoe_size, :as => :number, :input_html => { :min => 3, :max => 15, :step => 1, :class => "special" } %>
|
60
|
+
#
|
61
|
+
# @example Min/max/step also work as options
|
62
|
+
# <%= f.input :shoe_size, :as => :number, :min => 3, :max => 15, :step => 1, :input_html => { :class => "special" } %>
|
63
|
+
#
|
64
|
+
# @example Use :in with a Range as a shortcut for :min/:max
|
65
|
+
# <%= f.input :shoe_size, :as => :number, :in => 3..15, :step => 1 %>
|
66
|
+
# <%= f.input :shoe_size, :as => :number, :input_html => { :in => 3..15, :step => 1 } %>
|
67
|
+
#
|
68
|
+
# @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
|
69
|
+
# @see http://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_numericality_of Rails' Numericality validation documentation
|
70
|
+
class NumberInput
|
71
|
+
include Base
|
72
|
+
include Base::Numeric
|
73
|
+
include Base::Placeholder
|
74
|
+
|
75
|
+
def to_html
|
76
|
+
input_wrapping do
|
77
|
+
label_html <<
|
78
|
+
builder.number_field(method, input_html_options)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def step_option
|
83
|
+
super || "any"
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|