mega-safe-tool 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/formtastic-6.0.0/Appraisals +23 -0
- data/formtastic-6.0.0/CONTRIBUTING.md +27 -0
- data/formtastic-6.0.0/Gemfile +8 -0
- data/formtastic-6.0.0/MIT-LICENSE +20 -0
- data/formtastic-6.0.0/README.md +600 -0
- data/formtastic-6.0.0/RELEASE_PROCESS +7 -0
- data/formtastic-6.0.0/Rakefile +54 -0
- data/formtastic-6.0.0/bin/appraisal +8 -0
- data/formtastic-6.0.0/formtastic.gemspec +45 -0
- data/formtastic-6.0.0/gemfiles/rails_72.gemfile +9 -0
- data/formtastic-6.0.0/gemfiles/rails_80.gemfile +9 -0
- data/formtastic-6.0.0/gemfiles/rails_81.gemfile +9 -0
- data/formtastic-6.0.0/gemfiles/rails_edge.gemfile +9 -0
- data/formtastic-6.0.0/lib/formtastic/action_class_finder.rb +19 -0
- data/formtastic-6.0.0/lib/formtastic/actions/base.rb +157 -0
- data/formtastic-6.0.0/lib/formtastic/actions/button_action.rb +68 -0
- data/formtastic-6.0.0/lib/formtastic/actions/buttonish.rb +18 -0
- data/formtastic-6.0.0/lib/formtastic/actions/input_action.rb +71 -0
- data/formtastic-6.0.0/lib/formtastic/actions/link_action.rb +89 -0
- data/formtastic-6.0.0/lib/formtastic/actions.rb +15 -0
- data/formtastic-6.0.0/lib/formtastic/deprecation.rb +6 -0
- data/formtastic-6.0.0/lib/formtastic/form_builder.rb +109 -0
- data/formtastic-6.0.0/lib/formtastic/helpers/action_helper.rb +115 -0
- data/formtastic-6.0.0/lib/formtastic/helpers/actions_helper.rb +169 -0
- data/formtastic-6.0.0/lib/formtastic/helpers/enum.rb +14 -0
- data/formtastic-6.0.0/lib/formtastic/helpers/errors_helper.rb +139 -0
- data/formtastic-6.0.0/lib/formtastic/helpers/fieldset_wrapper.rb +85 -0
- data/formtastic-6.0.0/lib/formtastic/helpers/file_column_detection.rb +17 -0
- data/formtastic-6.0.0/lib/formtastic/helpers/form_helper.rb +204 -0
- data/formtastic-6.0.0/lib/formtastic/helpers/input_helper.rb +349 -0
- data/formtastic-6.0.0/lib/formtastic/helpers/inputs_helper.rb +421 -0
- data/formtastic-6.0.0/lib/formtastic/helpers/reflection.rb +38 -0
- data/formtastic-6.0.0/lib/formtastic/helpers.rb +16 -0
- data/formtastic-6.0.0/lib/formtastic/html_attributes.rb +33 -0
- data/formtastic-6.0.0/lib/formtastic/i18n.rb +33 -0
- data/formtastic-6.0.0/lib/formtastic/input_class_finder.rb +19 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/aria.rb +26 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/associations.rb +32 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/choices.rb +109 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/collections.rb +158 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/database.rb +20 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/datetime_pickerish.rb +86 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/errors.rb +59 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/fileish.rb +24 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/hints.rb +32 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/html.rb +54 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/labelling.rb +53 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/naming.rb +43 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/numeric.rb +51 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/options.rb +18 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/placeholder.rb +18 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/stringish.rb +39 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/timeish.rb +246 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/validations.rb +250 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base/wrapping.rb +51 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/base.rb +79 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/boolean_input.rb +119 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/check_boxes_input.rb +198 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/color_input.rb +42 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/country_input.rb +90 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/datalist_input.rb +42 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/date_picker_input.rb +94 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/date_select_input.rb +35 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/datetime_picker_input.rb +104 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/datetime_select_input.rb +13 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/email_input.rb +42 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/file_input.rb +43 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/hidden_input.rb +63 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/number_input.rb +89 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/password_input.rb +42 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/phone_input.rb +43 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/radio_input.rb +164 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/range_input.rb +96 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/search_input.rb +42 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/select_input.rb +236 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/string_input.rb +37 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/text_input.rb +49 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/time_picker_input.rb +100 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/time_select_input.rb +39 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/time_zone_input.rb +59 -0
- data/formtastic-6.0.0/lib/formtastic/inputs/url_input.rb +42 -0
- data/formtastic-6.0.0/lib/formtastic/inputs.rb +43 -0
- data/formtastic-6.0.0/lib/formtastic/localized_string.rb +18 -0
- data/formtastic-6.0.0/lib/formtastic/localizer.rb +151 -0
- data/formtastic-6.0.0/lib/formtastic/namespaced_class_finder.rb +98 -0
- data/formtastic-6.0.0/lib/formtastic/version.rb +4 -0
- data/formtastic-6.0.0/lib/formtastic.rb +48 -0
- data/formtastic-6.0.0/lib/generators/formtastic/form/form_generator.rb +111 -0
- data/formtastic-6.0.0/lib/generators/formtastic/input/input_generator.rb +47 -0
- data/formtastic-6.0.0/lib/generators/formtastic/install/install_generator.rb +23 -0
- data/formtastic-6.0.0/lib/generators/formtastic/stylesheets/stylesheets_generator.rb +15 -0
- data/formtastic-6.0.0/lib/generators/templates/_form.html.erb +11 -0
- data/formtastic-6.0.0/lib/generators/templates/_form.html.haml +8 -0
- data/formtastic-6.0.0/lib/generators/templates/_form.html.slim +8 -0
- data/formtastic-6.0.0/lib/generators/templates/formtastic.css +289 -0
- data/formtastic-6.0.0/lib/generators/templates/formtastic.rb +118 -0
- data/formtastic-6.0.0/lib/generators/templates/input.rb +19 -0
- data/formtastic-6.0.0/lib/locale/en.yml +10 -0
- data/formtastic-6.0.0/sample/basic_inputs.html +224 -0
- data/formtastic-6.0.0/sample/config.ru +69 -0
- data/formtastic-6.0.0/sample/index.html +14 -0
- data/formtastic-6.0.0/script/integration-template.rb +76 -0
- data/formtastic-6.0.0/script/integration.sh +32 -0
- data/formtastic-6.0.0/spec/action_class_finder_spec.rb +12 -0
- data/formtastic-6.0.0/spec/actions/button_action_spec.rb +63 -0
- data/formtastic-6.0.0/spec/actions/generic_action_spec.rb +521 -0
- data/formtastic-6.0.0/spec/actions/input_action_spec.rb +59 -0
- data/formtastic-6.0.0/spec/actions/link_action_spec.rb +92 -0
- data/formtastic-6.0.0/spec/builder/custom_builder_spec.rb +132 -0
- data/formtastic-6.0.0/spec/builder/error_proc_spec.rb +27 -0
- data/formtastic-6.0.0/spec/builder/semantic_fields_for_spec.rb +213 -0
- data/formtastic-6.0.0/spec/fast_spec_helper.rb +12 -0
- data/formtastic-6.0.0/spec/generators/formtastic/form/form_generator_spec.rb +132 -0
- data/formtastic-6.0.0/spec/generators/formtastic/input/input_generator_spec.rb +125 -0
- data/formtastic-6.0.0/spec/generators/formtastic/install/install_generator_spec.rb +48 -0
- data/formtastic-6.0.0/spec/generators/formtastic/stylesheets/stylesheets_generator_spec.rb +22 -0
- data/formtastic-6.0.0/spec/helpers/action_helper_spec.rb +338 -0
- data/formtastic-6.0.0/spec/helpers/actions_helper_spec.rb +143 -0
- data/formtastic-6.0.0/spec/helpers/form_helper_spec.rb +224 -0
- data/formtastic-6.0.0/spec/helpers/input_helper_spec.rb +991 -0
- data/formtastic-6.0.0/spec/helpers/inputs_helper_spec.rb +669 -0
- data/formtastic-6.0.0/spec/helpers/reflection_helper_spec.rb +32 -0
- data/formtastic-6.0.0/spec/helpers/semantic_errors_helper_spec.rb +220 -0
- data/formtastic-6.0.0/spec/i18n_spec.rb +210 -0
- data/formtastic-6.0.0/spec/input_class_finder_spec.rb +10 -0
- data/formtastic-6.0.0/spec/inputs/base/collections_spec.rb +119 -0
- data/formtastic-6.0.0/spec/inputs/base/validations_spec.rb +481 -0
- data/formtastic-6.0.0/spec/inputs/boolean_input_spec.rb +254 -0
- data/formtastic-6.0.0/spec/inputs/check_boxes_input_spec.rb +547 -0
- data/formtastic-6.0.0/spec/inputs/color_input_spec.rb +85 -0
- data/formtastic-6.0.0/spec/inputs/country_input_spec.rb +133 -0
- data/formtastic-6.0.0/spec/inputs/custom_input_spec.rb +51 -0
- data/formtastic-6.0.0/spec/inputs/datalist_input_spec.rb +61 -0
- data/formtastic-6.0.0/spec/inputs/date_picker_input_spec.rb +449 -0
- data/formtastic-6.0.0/spec/inputs/date_select_input_spec.rb +249 -0
- data/formtastic-6.0.0/spec/inputs/datetime_picker_input_spec.rb +490 -0
- data/formtastic-6.0.0/spec/inputs/datetime_select_input_spec.rb +209 -0
- data/formtastic-6.0.0/spec/inputs/email_input_spec.rb +85 -0
- data/formtastic-6.0.0/spec/inputs/file_input_spec.rb +89 -0
- data/formtastic-6.0.0/spec/inputs/hidden_input_spec.rb +135 -0
- data/formtastic-6.0.0/spec/inputs/include_blank_spec.rb +78 -0
- data/formtastic-6.0.0/spec/inputs/label_spec.rb +181 -0
- data/formtastic-6.0.0/spec/inputs/number_input_spec.rb +815 -0
- data/formtastic-6.0.0/spec/inputs/password_input_spec.rb +99 -0
- data/formtastic-6.0.0/spec/inputs/phone_input_spec.rb +85 -0
- data/formtastic-6.0.0/spec/inputs/placeholder_spec.rb +71 -0
- data/formtastic-6.0.0/spec/inputs/radio_input_spec.rb +326 -0
- data/formtastic-6.0.0/spec/inputs/range_input_spec.rb +505 -0
- data/formtastic-6.0.0/spec/inputs/readonly_spec.rb +50 -0
- data/formtastic-6.0.0/spec/inputs/search_input_spec.rb +84 -0
- data/formtastic-6.0.0/spec/inputs/select_input_spec.rb +661 -0
- data/formtastic-6.0.0/spec/inputs/string_input_spec.rb +326 -0
- data/formtastic-6.0.0/spec/inputs/text_input_spec.rb +187 -0
- data/formtastic-6.0.0/spec/inputs/time_picker_input_spec.rb +455 -0
- data/formtastic-6.0.0/spec/inputs/time_select_input_spec.rb +261 -0
- data/formtastic-6.0.0/spec/inputs/time_zone_input_spec.rb +143 -0
- data/formtastic-6.0.0/spec/inputs/url_input_spec.rb +85 -0
- data/formtastic-6.0.0/spec/inputs/with_options_spec.rb +43 -0
- data/formtastic-6.0.0/spec/localizer_spec.rb +130 -0
- data/formtastic-6.0.0/spec/namespaced_class_finder_spec.rb +90 -0
- data/formtastic-6.0.0/spec/schema.rb +22 -0
- data/formtastic-6.0.0/spec/spec.opts +2 -0
- data/formtastic-6.0.0/spec/spec_helper.rb +466 -0
- data/formtastic-6.0.0/spec/support/custom_macros.rb +570 -0
- data/formtastic-6.0.0/spec/support/deprecation.rb +7 -0
- data/formtastic-6.0.0/spec/support/shared_examples.rb +13 -0
- data/formtastic-6.0.0/spec/support/specialized_class_finder_shared_example.rb +27 -0
- data/formtastic-6.0.0/spec/support/test_environment.rb +46 -0
- data/mega-safe-tool.gemspec +11 -0
- metadata +209 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Formtastic
|
|
3
|
+
module Inputs
|
|
4
|
+
|
|
5
|
+
# Outputs a simple `<label>` with a HTML5 `<input type="range">` wrapped in the standard
|
|
6
|
+
# `<li>` wrapper. This is an alternative input choice to a number input.
|
|
7
|
+
#
|
|
8
|
+
# Sensible default for the `min`, `max` and `step` attributes are found by reflecting on
|
|
9
|
+
# the model's validations. When validations are not provided, the `min` and `step` default to
|
|
10
|
+
# `1` and the `max` default to `100`. 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 => :range %>
|
|
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="range" id="user_shoe_size" name="user[shoe_size]" min="1" max="100" step="1">
|
|
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="range" 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 => :range, :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 => :range, :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 => :range, :in => 3..15, :step => 1 %>
|
|
66
|
+
# <%= f.input :shoe_size, :as => :range, :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 https://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_numericality_of Rails' Numericality validation documentation
|
|
70
|
+
#
|
|
71
|
+
class RangeInput
|
|
72
|
+
include Base
|
|
73
|
+
include Base::Numeric
|
|
74
|
+
|
|
75
|
+
def to_html
|
|
76
|
+
input_wrapping do
|
|
77
|
+
label_html <<
|
|
78
|
+
builder.range_field(method, input_html_options)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def min_option
|
|
83
|
+
super || 1
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def max_option
|
|
87
|
+
super || 100
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def step_option
|
|
91
|
+
super || 1
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Formtastic
|
|
3
|
+
module Inputs
|
|
4
|
+
|
|
5
|
+
# Outputs a simple `<label>` with a HTML5 `<input type="search">` wrapped in the standard
|
|
6
|
+
# `<li>` wrapper. This is the default input choice for attributes with a name matching
|
|
7
|
+
# `/^search$/`, but can be applied to any text-like input with `:as => :search`.
|
|
8
|
+
#
|
|
9
|
+
# @example Full form context and output
|
|
10
|
+
#
|
|
11
|
+
# <%= semantic_form_for(@search, :html => { :method => :get }) do |f| %>
|
|
12
|
+
# <%= f.inputs do %>
|
|
13
|
+
# <%= f.input :q, :as => :search, :label => false, :input_html => { :name => "q" } %>
|
|
14
|
+
# <% end %>
|
|
15
|
+
# <% end %>
|
|
16
|
+
#
|
|
17
|
+
# <form...>
|
|
18
|
+
# <fieldset>
|
|
19
|
+
# <ol>
|
|
20
|
+
# <li class="search">
|
|
21
|
+
# <input type="search" id="search_q" name="q">
|
|
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 SearchInput
|
|
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.search_field(method, input_html_options)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Formtastic
|
|
3
|
+
module Inputs
|
|
4
|
+
# A select input is used to render a `<select>` tag with a series of options to choose from.
|
|
5
|
+
# It works for both single selections (like a `belongs_to` relationship, or "yes/no" boolean),
|
|
6
|
+
# as well as multiple selections (like a `has_and_belongs_to_many`/`has_many` relationship,
|
|
7
|
+
# for assigning many genres to a song, for example).
|
|
8
|
+
#
|
|
9
|
+
# This is the default input choice when:
|
|
10
|
+
#
|
|
11
|
+
# * the database column type is an `:integer` and there is an association (`belongs_to`)
|
|
12
|
+
# * the database column type is an `:integer` and there is an enum defined (`enum`)
|
|
13
|
+
# * the database column type is a `:string` and the `:collection` option is used
|
|
14
|
+
# * there an object with an association, but no database column on the object (`has_many`, etc)
|
|
15
|
+
# * there is no object and the `:collection` option is used
|
|
16
|
+
#
|
|
17
|
+
# The flexibility of the `:collection` option (see examples) makes the :select input viable as
|
|
18
|
+
# an alternative for many other input types. For example, instead of...
|
|
19
|
+
#
|
|
20
|
+
# * a `:string` input (where you want to force the user to choose from a few specific strings rather than entering anything)
|
|
21
|
+
# * a `:boolean` checkbox input (where the user could choose yes or no, rather than checking a box)
|
|
22
|
+
# * a `:date_select`, `:time_select` or `:datetime_select` input (where the user could choose from pre-selected dates)
|
|
23
|
+
# * a `:number` input (where the user could choose from a set of pre-defined numbers)
|
|
24
|
+
# * a `:time_zone` input (where you want to provide your own set of choices instead of relying on Rails)
|
|
25
|
+
# * a `:country` input (no need for a plugin really)
|
|
26
|
+
#
|
|
27
|
+
# Within the standard `<li>` wrapper, the output is a `<label>` tag followed by a `<select>`
|
|
28
|
+
# tag containing `<option>` tags.
|
|
29
|
+
#
|
|
30
|
+
# For inputs that map to associations on the object model, Formtastic will automatically load
|
|
31
|
+
# in a collection of objects on the association as options to choose from. This might be an
|
|
32
|
+
# `Author.all` on a `Post` form with an input for a `belongs_to :user` association, or a
|
|
33
|
+
# `Tag.all` for a `Post` form with an input for a `has_and_belongs_to_many :tags` association.
|
|
34
|
+
# You can override or customise this collection and the `<option>` tags it will render through
|
|
35
|
+
# the `:collection` option (see examples).
|
|
36
|
+
#
|
|
37
|
+
# The way on which Formtastic renders the `value` attribute and content of each `<option>` tag
|
|
38
|
+
# is customisable through the `:member_label` and `:member_value` options. When not provided,
|
|
39
|
+
# we fall back to a list of methods to try on each object such as `:to_label`, `:name` and
|
|
40
|
+
# `:to_s`, which are defined in the configurations `collection_label_methods` and
|
|
41
|
+
# `collection_value_methods` (see examples below).
|
|
42
|
+
#
|
|
43
|
+
# For select inputs that map to ActiveRecord `enum` attributes, Formtastic will automatically
|
|
44
|
+
# load in your enum options to be used as the select's options. This can be overridden with
|
|
45
|
+
# the `:collection` option, or augmented with I18n translations. See examples below.
|
|
46
|
+
# An error is raised if you try to render a multi-select with an enum, as ActiveRecord can
|
|
47
|
+
# only store one choice in the database.
|
|
48
|
+
#
|
|
49
|
+
#
|
|
50
|
+
# @example Basic `belongs_to` example with full form context
|
|
51
|
+
#
|
|
52
|
+
# <%= semantic_form_for @post do |f| %>
|
|
53
|
+
# <%= f.inputs do %>
|
|
54
|
+
# <%= f.input :author, :as => :select %>
|
|
55
|
+
# <% end %>
|
|
56
|
+
# <% end %>
|
|
57
|
+
#
|
|
58
|
+
# <form...>
|
|
59
|
+
# <fieldset>
|
|
60
|
+
# <ol>
|
|
61
|
+
# <li class='select'>
|
|
62
|
+
# <label for="post_author_id">Author</label>
|
|
63
|
+
# <select id="post_author_id" name="post[post_author_id]">
|
|
64
|
+
# <option value=""></option>
|
|
65
|
+
# <option value="1">Justin</option>
|
|
66
|
+
# <option value="3">Kate</option>
|
|
67
|
+
# <option value="2">Amelia</option>
|
|
68
|
+
# </select>
|
|
69
|
+
# </li>
|
|
70
|
+
# </ol>
|
|
71
|
+
# </fieldset>
|
|
72
|
+
# </form>
|
|
73
|
+
#
|
|
74
|
+
# @example Basic `has_many` or `has_and_belongs_to_many` example with full form context
|
|
75
|
+
#
|
|
76
|
+
# <%= semantic_form_for @post do |f| %>
|
|
77
|
+
# <%= f.inputs do %>
|
|
78
|
+
# <%= f.input :tags, :as => :select %>
|
|
79
|
+
# <% end %>
|
|
80
|
+
# <% end %>
|
|
81
|
+
#
|
|
82
|
+
# <form...>
|
|
83
|
+
# <fieldset>
|
|
84
|
+
# <ol>
|
|
85
|
+
# <li class='select'>
|
|
86
|
+
# <label for="post_tag_ids">Author</label>
|
|
87
|
+
# <select id="post_tag_ids" name="post[tag_ids]" multiple="true">
|
|
88
|
+
# <option value="1">Ruby</option>
|
|
89
|
+
# <option value="6">Rails</option>
|
|
90
|
+
# <option value="3">Forms</option>
|
|
91
|
+
# <option value="4">Awesome</option>
|
|
92
|
+
# </select>
|
|
93
|
+
# </li>
|
|
94
|
+
# </ol>
|
|
95
|
+
# </fieldset>
|
|
96
|
+
# </form>
|
|
97
|
+
#
|
|
98
|
+
# @example Override Formtastic's assumption on when you need a multi select
|
|
99
|
+
# <%= f.input :authors, :as => :select, :input_html => { :multiple => true } %>
|
|
100
|
+
# <%= f.input :authors, :as => :select, :input_html => { :multiple => false } %>
|
|
101
|
+
#
|
|
102
|
+
# @example The `:collection` option can be used to customize the choices
|
|
103
|
+
# <%= f.input :author, :as => :select, :collection => @authors %>
|
|
104
|
+
# <%= f.input :author, :as => :select, :collection => Author.all %>
|
|
105
|
+
# <%= f.input :author, :as => :select, :collection => Author.some_named_scope %>
|
|
106
|
+
# <%= f.input :author, :as => :select, :collection => Author.pluck(:full_name, :id) %>
|
|
107
|
+
# <%= f.input :author, :as => :select, :collection => Author.pluck(Arel.sql("CONCAT(`first_name`, ' ', `last_name`)"), :id)) %>
|
|
108
|
+
# <%= f.input :author, :as => :select, :collection => [Author.find_by_login("justin"), Category.find_by_name("kate")] %>
|
|
109
|
+
# <%= f.input :author, :as => :select, :collection => ["Justin", "Kate"] %>
|
|
110
|
+
# <%= f.input :author, :as => :select, :collection => [["Justin", "justin"], ["Kate", "kate"]] %>
|
|
111
|
+
# <%= f.input :author, :as => :select, :collection => [["Justin", "1"], ["Kate", "3"]] %>
|
|
112
|
+
# <%= f.input :author, :as => :select, :collection => [["Justin", 1], ["Kate", 3]] %>
|
|
113
|
+
# <%= f.input :author, :as => :select, :collection => 1..5 %>
|
|
114
|
+
# <%= f.input :author, :as => :select, :collection => "<option>your own options HTML string</option>" %>
|
|
115
|
+
# <%= f.input :author, :as => :select, :collection => options_for_select(...) %>
|
|
116
|
+
# <%= f.input :author, :as => :select, :collection => options_from_collection_for_select(...) %>
|
|
117
|
+
# <%= f.input :author, :as => :select, :collection => grouped_options_for_select(...) %>
|
|
118
|
+
# <%= f.input :author, :as => :select, :collection => time_zone_options_for_select(...) %>
|
|
119
|
+
#
|
|
120
|
+
# @example Set HTML attributes on the `<select>` tag with `:input_html`
|
|
121
|
+
# <%= f.input :authors, :as => :select, :input_html => { :size => 20, :multiple => true, :class => "special" } %>
|
|
122
|
+
#
|
|
123
|
+
# @example Set HTML attributes on the `<li>` wrapper with `:wrapper_html`
|
|
124
|
+
# <%= f.input :authors, :as => :select, :wrapper_html => { :class => "special" } %>
|
|
125
|
+
#
|
|
126
|
+
# @example Exclude, include, or customize the blank option at the top of the select. Always shown, even if the field already has a value. Suitable for optional inputs.
|
|
127
|
+
# <%= f.input :author, :as => :select, :include_blank => false %>
|
|
128
|
+
# <%= f.input :author, :as => :select, :include_blank => true %> => <option value=""></option>
|
|
129
|
+
# <%= f.input :author, :as => :select, :include_blank => "No author" %>
|
|
130
|
+
#
|
|
131
|
+
# @example Exclude, include, or customize the prompt at the top of the select. Only shown if the field does not have a value. Suitable for required inputs.
|
|
132
|
+
# <%= f.input :author, :as => :select, :prompt => false %>
|
|
133
|
+
# <%= f.input :author, :as => :select, :prompt => true %> => <option value="">Please select</option>
|
|
134
|
+
# <%= f.input :author, :as => :select, :prompt => "Please select an author" %>
|
|
135
|
+
#
|
|
136
|
+
# @example Using ActiveRecord enum attribute with i18n translation:
|
|
137
|
+
# # post.rb
|
|
138
|
+
# class Post < ActiveRecord::Base
|
|
139
|
+
# enum :status => [ :active, :archived ]
|
|
140
|
+
# end
|
|
141
|
+
# # en.yml
|
|
142
|
+
# en:
|
|
143
|
+
# activerecord:
|
|
144
|
+
# attributes:
|
|
145
|
+
# post:
|
|
146
|
+
# statuses:
|
|
147
|
+
# active: I am active!
|
|
148
|
+
# archived: I am archived!
|
|
149
|
+
# # form
|
|
150
|
+
# <%= f.input :status, :as => :select %>
|
|
151
|
+
#
|
|
152
|
+
# @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
|
|
153
|
+
# @see Formtastic::Inputs::CheckBoxesInput CheckBoxesInput as an alternative for `has_many` and `has_and_belongs_to_many` associations
|
|
154
|
+
# @see Formtastic::Inputs::RadioInput RadioInput as an alternative for `belongs_to` associations
|
|
155
|
+
#
|
|
156
|
+
# @todo Do/can we support the per-item HTML options like RadioInput?
|
|
157
|
+
class SelectInput
|
|
158
|
+
include Base
|
|
159
|
+
include Base::Collections
|
|
160
|
+
|
|
161
|
+
def initialize(*args)
|
|
162
|
+
super
|
|
163
|
+
raise Formtastic::UnsupportedEnumCollection if collection_from_enum? && multiple?
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def to_html
|
|
167
|
+
input_wrapping do
|
|
168
|
+
label_html <<
|
|
169
|
+
select_html
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def select_html
|
|
174
|
+
builder.select(input_name, collection, input_options, input_html_options)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def include_blank
|
|
178
|
+
options.key?(:include_blank) ? options[:include_blank] : (single? && builder.include_blank_for_select_by_default)
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def prompt?
|
|
182
|
+
!!options[:prompt]
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def label_html_options
|
|
186
|
+
super.merge(:for => input_html_options[:id])
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def input_options
|
|
190
|
+
super.merge :include_blank => (include_blank unless prompt?)
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def input_html_options
|
|
194
|
+
extra_input_html_options.merge(super.reject {|k,v| k==:name && v.nil?} )
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def extra_input_html_options
|
|
198
|
+
{
|
|
199
|
+
:multiple => multiple?,
|
|
200
|
+
:name => multiple? ? input_html_options_name_multiple : input_html_options_name
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def input_html_options_name
|
|
207
|
+
if builder.options.key?(:index)
|
|
208
|
+
"#{object_name}[#{builder.options[:index]}][#{association_primary_key}]"
|
|
209
|
+
else
|
|
210
|
+
"#{object_name}[#{association_primary_key}]"
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def input_html_options_name_multiple
|
|
215
|
+
input_html_options_name + "[]"
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
def multiple_by_association?
|
|
219
|
+
reflection && [ :has_many, :has_and_belongs_to_many ].include?(reflection.macro)
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def multiple_by_options?
|
|
223
|
+
options[:multiple] || (options[:input_html] && options[:input_html][:multiple])
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def multiple?
|
|
227
|
+
multiple_by_options? || multiple_by_association?
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
def single?
|
|
231
|
+
!multiple?
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Formtastic
|
|
3
|
+
module Inputs
|
|
4
|
+
|
|
5
|
+
# Outputs a simple `<label>` with a `<input type="text">` wrapped in the standard
|
|
6
|
+
# `<li>` wrapper. This is the default input choice for database columns of the `:string` type,
|
|
7
|
+
# and is the default choice for all inputs when no other logical input type can be inferred.
|
|
8
|
+
# You can force any input to be a string input with `:as => :string`.
|
|
9
|
+
#
|
|
10
|
+
# @example Full form context and output
|
|
11
|
+
#
|
|
12
|
+
# <%= semantic_form_for(@user) do |f| %>
|
|
13
|
+
# <%= f.inputs do %>
|
|
14
|
+
# <%= f.input :first_name, :as => :string %>
|
|
15
|
+
# <% end %>
|
|
16
|
+
# <% end %>
|
|
17
|
+
#
|
|
18
|
+
# <form...>
|
|
19
|
+
# <fieldset>
|
|
20
|
+
# <ol>
|
|
21
|
+
# <li class="string">
|
|
22
|
+
# <label for="user_first_name">First name</label>
|
|
23
|
+
# <input type="text" id="user_first_name" name="user[first_name]">
|
|
24
|
+
# </li>
|
|
25
|
+
# </ol>
|
|
26
|
+
# </fieldset>
|
|
27
|
+
# </form>
|
|
28
|
+
#
|
|
29
|
+
# @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
|
|
30
|
+
class StringInput
|
|
31
|
+
include Base
|
|
32
|
+
include Base::Stringish
|
|
33
|
+
include Base::Placeholder
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Formtastic
|
|
3
|
+
module Inputs
|
|
4
|
+
|
|
5
|
+
# Outputs a simple `<label>` with a `<textarea>` wrapped in the standard
|
|
6
|
+
# `<li>` wrapper. This is the default input choice for database columns of the `:text` type,
|
|
7
|
+
# but can forced on any text-like input with `:as => :text`.
|
|
8
|
+
#
|
|
9
|
+
# @example Full form context and output
|
|
10
|
+
#
|
|
11
|
+
# <%= semantic_form_for(@user) do |f| %>
|
|
12
|
+
# <%= f.inputs do %>
|
|
13
|
+
# <%= f.input :first_name, :as => :text %>
|
|
14
|
+
# <% end %>
|
|
15
|
+
# <% end %>
|
|
16
|
+
#
|
|
17
|
+
# <form...>
|
|
18
|
+
# <fieldset>
|
|
19
|
+
# <ol>
|
|
20
|
+
# <li class="text">
|
|
21
|
+
# <label for="user_first_name">First name</label>
|
|
22
|
+
# <textarea cols="30" id="user_first_name" name="user[first_name]" rows="20"></textarea>
|
|
23
|
+
# </li>
|
|
24
|
+
# </ol>
|
|
25
|
+
# </fieldset>
|
|
26
|
+
# </form>
|
|
27
|
+
#
|
|
28
|
+
# @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
|
|
29
|
+
class TextInput
|
|
30
|
+
include Base
|
|
31
|
+
include Base::Placeholder
|
|
32
|
+
|
|
33
|
+
def input_html_options
|
|
34
|
+
{
|
|
35
|
+
:cols => builder.default_text_area_width,
|
|
36
|
+
:rows => builder.default_text_area_height
|
|
37
|
+
}.merge(super)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def to_html
|
|
41
|
+
input_wrapping do
|
|
42
|
+
label_html <<
|
|
43
|
+
builder.text_area(method, input_html_options)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Formtastic
|
|
3
|
+
module Inputs
|
|
4
|
+
|
|
5
|
+
# Outputs a simple `<label>` with a HTML5 `<input type="time">` wrapped in the standard
|
|
6
|
+
# `<li>` wrapper. This is an alternative to `:time_select` for `:date`, `:time`, `:datetime`
|
|
7
|
+
# database columns. You can use this input with `:as => :time_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 => :time_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 5 for HH:MM)
|
|
35
|
+
# <%= f.input :publish_at, :as => :time_picker, :size => 20 %>
|
|
36
|
+
# <%= f.input :publish_at, :as => :time_picker, :input_html => { :size => 20 } %>
|
|
37
|
+
#
|
|
38
|
+
# @example Setting the maxlength (defaults to 5 for HH:MM)
|
|
39
|
+
# <%= f.input :publish_at, :as => :time_picker, :maxlength => 20 %>
|
|
40
|
+
# <%= f.input :publish_at, :as => :time_picker, :input_html => { :maxlength => 20 } %>
|
|
41
|
+
#
|
|
42
|
+
# @example Setting the value (defaults to HH:MM for Date and Time objects, otherwise renders string)
|
|
43
|
+
# <%= f.input :publish_at, :as => :time_picker, :input_html => { :value => "14:14" } %>
|
|
44
|
+
#
|
|
45
|
+
# @example Setting the step attribute (defaults to 60)
|
|
46
|
+
# <%= f.input :publish_at, :as => :time_picker, :step => 120 %>
|
|
47
|
+
# <%= f.input :publish_at, :as => :time_picker, :input_html => { :step => 120 } %>
|
|
48
|
+
#
|
|
49
|
+
# @example Setting the step attribute with a macro
|
|
50
|
+
# <%= f.input :publish_at, :as => :time_picker, :step => :second %>
|
|
51
|
+
# <%= f.input :publish_at, :as => :time_picker, :step => :minute %>
|
|
52
|
+
# <%= f.input :publish_at, :as => :time_picker, :step => :quarter_hour %>
|
|
53
|
+
# <%= f.input :publish_at, :as => :time_picker, :step => :fifteen_minutes %>
|
|
54
|
+
# <%= f.input :publish_at, :as => :time_picker, :step => :half_hour %>
|
|
55
|
+
# <%= f.input :publish_at, :as => :time_picker, :step => :thirty_minutes %>
|
|
56
|
+
# <%= f.input :publish_at, :as => :time_picker, :step => :hour %>
|
|
57
|
+
# <%= f.input :publish_at, :as => :time_picker, :step => :sixty_minutes %>
|
|
58
|
+
#
|
|
59
|
+
# @example Setting the min attribute
|
|
60
|
+
# <%= f.input :publish_at, :as => :time_picker, :min => "09:00" %>
|
|
61
|
+
# <%= f.input :publish_at, :as => :time_picker, :input_html => { :min => "01:00" } %>
|
|
62
|
+
#
|
|
63
|
+
# @example Setting the max attribute
|
|
64
|
+
# <%= f.input :publish_at, :as => :time_picker, :max => "18:00" %>
|
|
65
|
+
# <%= f.input :publish_at, :as => :time_picker, :input_html => { :max => "18:00" } %>
|
|
66
|
+
#
|
|
67
|
+
# @example Setting the placeholder attribute
|
|
68
|
+
# <%= f.input :publish_at, :as => :time_picker, :placeholder => "HH:MM" %>
|
|
69
|
+
# <%= f.input :publish_at, :as => :time_picker, :input_html => { :placeholder => "HH:MM" } %>
|
|
70
|
+
#
|
|
71
|
+
# @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
|
|
72
|
+
class TimePickerInput
|
|
73
|
+
include Base
|
|
74
|
+
include Base::Stringish
|
|
75
|
+
include Base::DatetimePickerish
|
|
76
|
+
|
|
77
|
+
def html_input_type
|
|
78
|
+
"time"
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def default_size
|
|
82
|
+
5
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def value
|
|
86
|
+
return options[:input_html][:value] if options[:input_html] && options[:input_html].key?(:value)
|
|
87
|
+
val = object.send(method)
|
|
88
|
+
return "00:00" if val.is_a?(Date)
|
|
89
|
+
return val.strftime("%H:%M") if val.is_a?(Time)
|
|
90
|
+
return val if val.nil?
|
|
91
|
+
val.to_s
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def default_step
|
|
95
|
+
60
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Formtastic
|
|
3
|
+
module Inputs
|
|
4
|
+
# Outputs a series of select boxes for the fragments that make up a time (hour, minute, second).
|
|
5
|
+
# Unless `:ignore_date` is true, it will render hidden inputs for the year, month and day as
|
|
6
|
+
# well, defaulting to `Time.current` if the form object doesn't have a value, much like Rails'
|
|
7
|
+
# own `time_select`.
|
|
8
|
+
#
|
|
9
|
+
# @see Formtastic::Inputs::Base::Timeish Timeish module for documentation of date, time and datetime input options.
|
|
10
|
+
class TimeSelectInput
|
|
11
|
+
include Base
|
|
12
|
+
include Base::Timeish
|
|
13
|
+
|
|
14
|
+
# we don't want year / month / day fragments if :ignore_date => true
|
|
15
|
+
def fragments
|
|
16
|
+
time_fragments
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def value_or_default_value
|
|
20
|
+
value ? value : Time.current
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def fragment_value(fragment)
|
|
24
|
+
value_or_default_value.send(fragment)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def hidden_fragments
|
|
28
|
+
if !options[:ignore_date]
|
|
29
|
+
date_fragments.map do |fragment|
|
|
30
|
+
template.hidden_field_tag(hidden_field_name(fragment), fragment_value(fragment), :id => fragment_id(fragment), :disabled => input_html_options[:disabled] )
|
|
31
|
+
end.join.html_safe
|
|
32
|
+
else
|
|
33
|
+
super
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Formtastic
|
|
3
|
+
module Inputs
|
|
4
|
+
|
|
5
|
+
# Outputs a `<label>` with a `<select>` containing a series of time zones (using Rails' own
|
|
6
|
+
# `time_zone_select` helper), wrapped in the standard `<li>` wrapper.
|
|
7
|
+
|
|
8
|
+
# This is the default input choice for attributes matching /time_zone/, but can be applied to
|
|
9
|
+
# any text-like input with `:as => :time_zone`.
|
|
10
|
+
#
|
|
11
|
+
# @example Full form context and output
|
|
12
|
+
#
|
|
13
|
+
# <%= semantic_form_for(@user) do |f| %>
|
|
14
|
+
# <%= f.inputs do %>
|
|
15
|
+
# <%= f.input :time_zone, :as => :time_zone %>
|
|
16
|
+
# <% end %>
|
|
17
|
+
# <% end %>
|
|
18
|
+
#
|
|
19
|
+
# <form...>
|
|
20
|
+
# <fieldset>
|
|
21
|
+
# <ol>
|
|
22
|
+
# <li class="time_zone">
|
|
23
|
+
# <label for="user_time_zone">Time zone</label>
|
|
24
|
+
# <input type="text" id="user_time_zone" name="user[time_zone]">
|
|
25
|
+
# </li>
|
|
26
|
+
# </ol>
|
|
27
|
+
# </fieldset>
|
|
28
|
+
# </form>
|
|
29
|
+
#
|
|
30
|
+
# @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
|
|
31
|
+
#
|
|
32
|
+
# The priority_zones option:
|
|
33
|
+
# Since this input actually uses Rails' `time_zone_select` helper, the :priority_zones
|
|
34
|
+
# option needs to be an array of ActiveSupport::TimeZone objects.
|
|
35
|
+
#
|
|
36
|
+
# And you can configure default value using
|
|
37
|
+
#
|
|
38
|
+
# ```
|
|
39
|
+
# Formtastic::FormBuilder.priority_time_zones = [timezone1, timezone2]
|
|
40
|
+
# ```
|
|
41
|
+
#
|
|
42
|
+
# See https://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/time_zone_select for more information.
|
|
43
|
+
#
|
|
44
|
+
class TimeZoneInput
|
|
45
|
+
include Base
|
|
46
|
+
|
|
47
|
+
def to_html
|
|
48
|
+
input_wrapping do
|
|
49
|
+
label_html <<
|
|
50
|
+
builder.time_zone_select(method, priority_zones, input_options, input_html_options)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def priority_zones
|
|
55
|
+
options[:priority_zones] || Formtastic::FormBuilder.priority_time_zones
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|