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,35 @@
|
|
|
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 date (year, month, day).
|
|
5
|
+
#
|
|
6
|
+
# @see Formtastic::Inputs::Base::Timeish Timeish module for documentation of date, time and datetime input options.
|
|
7
|
+
class DateSelectInput
|
|
8
|
+
include Base
|
|
9
|
+
include Base::Timeish
|
|
10
|
+
|
|
11
|
+
# We don't want hour and minute fragments on a date input
|
|
12
|
+
def time_fragments
|
|
13
|
+
[]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def hidden_date_fragments
|
|
17
|
+
default_date_fragments - date_fragments
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def hidden_fragments
|
|
21
|
+
hidden_date_fragments.map do |fragment|
|
|
22
|
+
template.hidden_field_tag(hidden_field_name(fragment), fragment_value(fragment), :id => fragment_id(fragment), :disabled => input_html_options[:disabled] )
|
|
23
|
+
end.join.html_safe
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def fragment_value(fragment)
|
|
27
|
+
if fragment == :year
|
|
28
|
+
Time.now.year
|
|
29
|
+
else
|
|
30
|
+
'1'
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Formtastic
|
|
3
|
+
module Inputs
|
|
4
|
+
|
|
5
|
+
# Outputs a simple `<label>` with a HTML5 `<input type="datetime-local">` (or
|
|
6
|
+
# `<input type="datetime">`) wrapped in the standard `<li>` wrapper. This is an alternative to
|
|
7
|
+
# `:date_select` for `:date`, `:time`, `:datetime` database columns. You can use this input with
|
|
8
|
+
# `:as => :datetime_picker`.
|
|
9
|
+
#
|
|
10
|
+
# *Please note:* Formtastic only provides suitable markup for a date picker, but does not supply
|
|
11
|
+
# any additional CSS or Javascript to render calendar-style date pickers. Browsers that support
|
|
12
|
+
# this input type (such as Mobile Webkit and Opera on the desktop) will render a native widget.
|
|
13
|
+
# Browsers that don't will default to a plain text field`<input type="text">` and can be
|
|
14
|
+
# poly-filled with some Javascript and a UI library of your choice.
|
|
15
|
+
#
|
|
16
|
+
# @example Full form context and output
|
|
17
|
+
#
|
|
18
|
+
# <%= semantic_form_for(@post) do |f| %>
|
|
19
|
+
# <%= f.inputs do %>
|
|
20
|
+
# <%= f.input :publish_at, :as => :datetime_picker %>
|
|
21
|
+
# <% end %>
|
|
22
|
+
# <% end %>
|
|
23
|
+
#
|
|
24
|
+
# <form...>
|
|
25
|
+
# <fieldset>
|
|
26
|
+
# <ol>
|
|
27
|
+
# <li class="string">
|
|
28
|
+
# <label for="post_publish_at">First name</label>
|
|
29
|
+
# <input type="date" id="post_publish_at" name="post[publish_at]">
|
|
30
|
+
# </li>
|
|
31
|
+
# </ol>
|
|
32
|
+
# </fieldset>
|
|
33
|
+
# </form>
|
|
34
|
+
#
|
|
35
|
+
# @example Setting the size (defaults to 16 for YYYY-MM-DD HH:MM)
|
|
36
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :size => 20 %>
|
|
37
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :input_html => { :size => 20 } %>
|
|
38
|
+
#
|
|
39
|
+
# @example Setting the maxlength (defaults to 16 for YYYY-MM-DD HH:MM)
|
|
40
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :maxlength => 20 %>
|
|
41
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :input_html => { :maxlength => 20 } %>
|
|
42
|
+
#
|
|
43
|
+
# @example Setting the value (defaults to YYYY-MM-DD HH:MM for Date and Time objects, otherwise renders string)
|
|
44
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :input_html => { :value => "1970-01-01 00:00" } %>
|
|
45
|
+
#
|
|
46
|
+
# @example Setting the step attribute (defaults to 1)
|
|
47
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :step => 60 %>
|
|
48
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :input_html => { :step => 60 } %>
|
|
49
|
+
#
|
|
50
|
+
# @example Setting the step attribute with a macro
|
|
51
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :step => :second %>
|
|
52
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :step => :minute %>
|
|
53
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :step => :quarter_hour %>
|
|
54
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :step => :fifteen_minutes %>
|
|
55
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :step => :half_hour %>
|
|
56
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :step => :thirty_minutes %>
|
|
57
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :step => :hour %>
|
|
58
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :step => :sixty_minutes %>
|
|
59
|
+
#
|
|
60
|
+
# @example Setting the min attribute
|
|
61
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :min => "2012-01-01 09:00" %>
|
|
62
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :input_html => { :min => "2012-01-01 09:00" } %>
|
|
63
|
+
#
|
|
64
|
+
# @example Setting the max attribute
|
|
65
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :max => "2012-12-31 16:00" %>
|
|
66
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :input_html => { :max => "2012-12-31 16:00" } %>
|
|
67
|
+
#
|
|
68
|
+
# @example Setting the placeholder attribute
|
|
69
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :placeholder => "YYYY-MM-DD HH:MM" %>
|
|
70
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :input_html => { :placeholder => "YYYY-MM-DD HH:MM" } %>
|
|
71
|
+
#
|
|
72
|
+
# @example Using `type=datetime-local` with `:local` option (this is the default, and recommended for browser support on iOS7 and Chrome)
|
|
73
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :local => true %>
|
|
74
|
+
#
|
|
75
|
+
# @example Using `type=datetime` with `:local` option (not recommended)
|
|
76
|
+
# <%= f.input :publish_at, :as => :datetime_picker, :local => false %>
|
|
77
|
+
#
|
|
78
|
+
# @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
|
|
79
|
+
class DatetimePickerInput
|
|
80
|
+
include Base
|
|
81
|
+
include Base::Stringish
|
|
82
|
+
include Base::DatetimePickerish
|
|
83
|
+
|
|
84
|
+
def html_input_type
|
|
85
|
+
options[:local] = true unless options.key?(:local)
|
|
86
|
+
options[:local] ? "datetime-local" : "datetime"
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def default_size
|
|
90
|
+
16
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def value
|
|
94
|
+
return options[:input_html][:value] if options[:input_html] && options[:input_html].key?(:value)
|
|
95
|
+
val = object.send(method)
|
|
96
|
+
return val.strftime("%Y-%m-%dT%H:%M:%S") if val.is_a?(Time)
|
|
97
|
+
return "#{val.year}-#{val.month}-#{val.day}T00:00:00" if val.is_a?(Date)
|
|
98
|
+
return val if val.nil?
|
|
99
|
+
val.to_s
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Formtastic
|
|
3
|
+
module Inputs
|
|
4
|
+
|
|
5
|
+
# Outputs a series of select boxes for the fragments that make up a date and time (year, month, day, hour, minute, second).
|
|
6
|
+
#
|
|
7
|
+
# @see Formtastic::Inputs::Base::Timeish Timeish module for documentation of date, time and datetime input options.
|
|
8
|
+
class DatetimeSelectInput
|
|
9
|
+
include Base
|
|
10
|
+
include Base::Timeish
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
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="email">` wrapped in the standard
|
|
6
|
+
# `<li>` wrapper. This is the default input choice for attributes with a name matching
|
|
7
|
+
# `/email/`, but can be applied to any text-like input with `:as => :email`.
|
|
8
|
+
#
|
|
9
|
+
# @example Full form context and output
|
|
10
|
+
#
|
|
11
|
+
# <%= semantic_form_for(@user) do |f| %>
|
|
12
|
+
# <%= f.inputs do %>
|
|
13
|
+
# <%= f.input :email_address, :as => :email %>
|
|
14
|
+
# <% end %>
|
|
15
|
+
# <% end %>
|
|
16
|
+
#
|
|
17
|
+
# <form...>
|
|
18
|
+
# <fieldset>
|
|
19
|
+
# <ol>
|
|
20
|
+
# <li class="email">
|
|
21
|
+
# <label for="user_email_address">Email address</label>
|
|
22
|
+
# <input type="email" id="user_email_address" name="user[email_address]">
|
|
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 EmailInput
|
|
30
|
+
include Base
|
|
31
|
+
include Base::Stringish
|
|
32
|
+
include Base::Placeholder
|
|
33
|
+
|
|
34
|
+
def to_html
|
|
35
|
+
input_wrapping do
|
|
36
|
+
label_html <<
|
|
37
|
+
builder.email_field(method, input_html_options)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Formtastic
|
|
3
|
+
module Inputs
|
|
4
|
+
|
|
5
|
+
# Outputs a simple `<label>` with a `<input type="file">` wrapped in the standard
|
|
6
|
+
# `<li>` wrapper. This is the default input choice for objects with attributes that appear
|
|
7
|
+
# to be for file uploads, by detecting some common method names used by popular file upload
|
|
8
|
+
# libraries such as Paperclip and CarrierWave. You can add to or alter these method names
|
|
9
|
+
# through the `file_methods` config, but can be applied to any input with `:as => :file`.
|
|
10
|
+
#
|
|
11
|
+
# Don't forget to set the multipart attribute in your `<form>` tag!
|
|
12
|
+
#
|
|
13
|
+
# @example Full form context and output
|
|
14
|
+
#
|
|
15
|
+
# <%= semantic_form_for(@user, :html => { :multipart => true }) do |f| %>
|
|
16
|
+
# <%= f.inputs do %>
|
|
17
|
+
# <%= f.input :avatar, :as => :file %>
|
|
18
|
+
# <% end %>
|
|
19
|
+
# <% end %>
|
|
20
|
+
#
|
|
21
|
+
# <form...>
|
|
22
|
+
# <fieldset>
|
|
23
|
+
# <ol>
|
|
24
|
+
# <li class="file">
|
|
25
|
+
# <label for="user_avatar">Avatar</label>
|
|
26
|
+
# <input type="file" id="user_avatar" name="user[avatar]">
|
|
27
|
+
# </li>
|
|
28
|
+
# </ol>
|
|
29
|
+
# </fieldset>
|
|
30
|
+
# </form>
|
|
31
|
+
#
|
|
32
|
+
# @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
|
|
33
|
+
class FileInput
|
|
34
|
+
include Base
|
|
35
|
+
def to_html
|
|
36
|
+
input_wrapping do
|
|
37
|
+
label_html <<
|
|
38
|
+
builder.file_field(method, input_html_options)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Formtastic
|
|
3
|
+
module Inputs
|
|
4
|
+
|
|
5
|
+
# Outputs a simple `<input type="hidden">` wrapped in the standard `<li>` wrapper. This is
|
|
6
|
+
# provided for situations where a hidden field needs to be rendered in the flow of a form with
|
|
7
|
+
# many inputs that form an `<ol>`. Wrapping the hidden input inside the `<li>` maintains the
|
|
8
|
+
# HTML validity. The `<li>` is marked with a `class` of `hidden` so that stylesheet authors can
|
|
9
|
+
# hide these list items with CSS (formtastic.css does this out of the box).
|
|
10
|
+
#
|
|
11
|
+
# @example Full form context, output and CSS
|
|
12
|
+
#
|
|
13
|
+
# <%= semantic_form_for(@something) do |f| %>
|
|
14
|
+
# <%= f.inputs do %>
|
|
15
|
+
# <%= f.input :secret, :as => :hidden %>
|
|
16
|
+
# <% end %>
|
|
17
|
+
# <% end %>
|
|
18
|
+
#
|
|
19
|
+
# <form...>
|
|
20
|
+
# <fieldset>
|
|
21
|
+
# <ol>
|
|
22
|
+
# <li class="hidden">
|
|
23
|
+
# <input type="hidden" id="something_secret" name="something[secret]">
|
|
24
|
+
# </li>
|
|
25
|
+
# </ol>
|
|
26
|
+
# </fieldset>
|
|
27
|
+
# </form>
|
|
28
|
+
#
|
|
29
|
+
# form.formtastic li.hidden { display:none; }
|
|
30
|
+
#
|
|
31
|
+
# @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
|
|
32
|
+
class HiddenInput
|
|
33
|
+
include Base
|
|
34
|
+
|
|
35
|
+
def input_html_options
|
|
36
|
+
super.merge(:required => nil).merge(:autofocus => nil)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def to_html
|
|
40
|
+
input_wrapping do
|
|
41
|
+
builder.hidden_field(method, input_html_options)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def error_html
|
|
46
|
+
+""
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def errors?
|
|
50
|
+
false
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def hint_html
|
|
54
|
+
+""
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def hint?
|
|
58
|
+
false
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Formtastic
|
|
3
|
+
module Inputs
|
|
4
|
+
|
|
5
|
+
# Outputs a simple `<label>` with a HTML5 `<input type="number">` wrapped in the standard
|
|
6
|
+
# `<li>` wrapper. This is the default input choice for all database columns of the type `:float`
|
|
7
|
+
# and `:decimal`, as well as `:integer` columns that aren't used for `belongs_to` associations,
|
|
8
|
+
# but can be applied to any text-like input with `:as => :number`.
|
|
9
|
+
#
|
|
10
|
+
# Sensible default values for the `min`, `max` and `step` attributes are found by reflecting on
|
|
11
|
+
# the model's validations (when provided). An `IndeterminableMinimumAttributeError` exception
|
|
12
|
+
# will be raised when the following conditions are all true:
|
|
13
|
+
#
|
|
14
|
+
# * you haven't specified a `:min` or `:max` for the input
|
|
15
|
+
# * the model's database column type is a `:float` or `:decimal`
|
|
16
|
+
# * the validation uses `:less_than` or `:greater_than`
|
|
17
|
+
#
|
|
18
|
+
# The solution is to either:
|
|
19
|
+
#
|
|
20
|
+
# * manually specify the `:min` or `:max` for the input
|
|
21
|
+
# * change the database column type to an `:integer` (if appropriate)
|
|
22
|
+
# * change the validations to use `:less_than_or_equal_to` or `:greater_than_or_equal_to`
|
|
23
|
+
#
|
|
24
|
+
# @example Full form context and output
|
|
25
|
+
#
|
|
26
|
+
# <%= semantic_form_for(@user) do |f| %>
|
|
27
|
+
# <%= f.inputs do %>
|
|
28
|
+
# <%= f.input :shoe_size, :as => :number %>
|
|
29
|
+
# <% end %>
|
|
30
|
+
# <% end %>
|
|
31
|
+
#
|
|
32
|
+
# <form...>
|
|
33
|
+
# <fieldset>
|
|
34
|
+
# <ol>
|
|
35
|
+
# <li class="numeric">
|
|
36
|
+
# <label for="user_shoe_size">Shoe size</label>
|
|
37
|
+
# <input type="number" id="user_shoe_size" name="user[shoe_size]">
|
|
38
|
+
# </li>
|
|
39
|
+
# </ol>
|
|
40
|
+
# </fieldset>
|
|
41
|
+
# </form>
|
|
42
|
+
#
|
|
43
|
+
# @example Default HTML5 min/max/step attributes are detected from the numericality validations
|
|
44
|
+
#
|
|
45
|
+
# class Person < ActiveRecord::Base
|
|
46
|
+
# validates_numericality_of :age,
|
|
47
|
+
# :less_than_or_equal_to => 100,
|
|
48
|
+
# :greater_than_or_equal_to => 18,
|
|
49
|
+
# :only_integer => true
|
|
50
|
+
# end
|
|
51
|
+
#
|
|
52
|
+
# <%= f.input :age, :as => :number %>
|
|
53
|
+
#
|
|
54
|
+
# <li class="numeric">
|
|
55
|
+
# <label for="persom_age">Age</label>
|
|
56
|
+
# <input type="number" id="person_age" name="person[age]" min="18" max="100" step="1">
|
|
57
|
+
# </li>
|
|
58
|
+
#
|
|
59
|
+
# @example Pass attributes down to the `<input>` tag with :input_html
|
|
60
|
+
# <%= f.input :shoe_size, :as => :number, :input_html => { :min => 3, :max => 15, :step => 1, :class => "special" } %>
|
|
61
|
+
#
|
|
62
|
+
# @example Min/max/step also work as options
|
|
63
|
+
# <%= f.input :shoe_size, :as => :number, :min => 3, :max => 15, :step => 1, :input_html => { :class => "special" } %>
|
|
64
|
+
#
|
|
65
|
+
# @example Use :in with a Range as a shortcut for :min/:max
|
|
66
|
+
# <%= f.input :shoe_size, :as => :number, :in => 3..15, :step => 1 %>
|
|
67
|
+
# <%= f.input :shoe_size, :as => :number, :input_html => { :in => 3..15, :step => 1 } %>
|
|
68
|
+
#
|
|
69
|
+
# @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
|
|
70
|
+
# @see https://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_numericality_of Rails' Numericality validation documentation
|
|
71
|
+
class NumberInput
|
|
72
|
+
include Base
|
|
73
|
+
include Base::Numeric
|
|
74
|
+
include Base::Placeholder
|
|
75
|
+
|
|
76
|
+
def to_html
|
|
77
|
+
input_wrapping do
|
|
78
|
+
label_html <<
|
|
79
|
+
builder.number_field(method, input_html_options)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def step_option
|
|
84
|
+
super || "any"
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Formtastic
|
|
3
|
+
module Inputs
|
|
4
|
+
|
|
5
|
+
# Outputs a simple `<label>` with a `<input type="password">` wrapped in the standard
|
|
6
|
+
# `<li>` wrapper. This is the default input choice for all attributes matching `/password/`, but
|
|
7
|
+
# can be applied to any text-like input with `:as => :password`.
|
|
8
|
+
#
|
|
9
|
+
# @example Full form context and output
|
|
10
|
+
#
|
|
11
|
+
# <%= semantic_form_for(@user) do |f| %>
|
|
12
|
+
# <%= f.inputs do %>
|
|
13
|
+
# <%= f.input :password, :as => :password %>
|
|
14
|
+
# <% end %>
|
|
15
|
+
# <% end %>
|
|
16
|
+
#
|
|
17
|
+
# <form...>
|
|
18
|
+
# <fieldset>
|
|
19
|
+
# <ol>
|
|
20
|
+
# <li class="password">
|
|
21
|
+
# <label for="user_password">Password</label>
|
|
22
|
+
# <input type="password" id="user_password" name="user[password]">
|
|
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 PasswordInput
|
|
30
|
+
include Base
|
|
31
|
+
include Base::Stringish
|
|
32
|
+
include Base::Placeholder
|
|
33
|
+
|
|
34
|
+
def to_html
|
|
35
|
+
input_wrapping do
|
|
36
|
+
label_html <<
|
|
37
|
+
builder.password_field(method, input_html_options)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Formtastic
|
|
3
|
+
module Inputs
|
|
4
|
+
|
|
5
|
+
# Outputs a simple `<label>` with a HTML5 `<input type="phone">` wrapped in the standard
|
|
6
|
+
# `<li>` wrapper. This is the default input choice for attributes with a name matching
|
|
7
|
+
# `/(phone|fax)/`, but can be applied to any text-like input with `:as => :phone`.
|
|
8
|
+
#
|
|
9
|
+
# @example Full form context and output
|
|
10
|
+
#
|
|
11
|
+
# <%= semantic_form_for(@user) do |f| %>
|
|
12
|
+
# <%= f.inputs do %>
|
|
13
|
+
# <%= f.input :mobile, :as => :phone %>
|
|
14
|
+
# <% end %>
|
|
15
|
+
# <% end %>
|
|
16
|
+
#
|
|
17
|
+
# <form...>
|
|
18
|
+
# <fieldset>
|
|
19
|
+
# <ol>
|
|
20
|
+
# <li class="phone">
|
|
21
|
+
# <label for="user_mobile">Mobile</label>
|
|
22
|
+
# <input type="tel" id="user_mobile" name="user[mobile]">
|
|
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 PhoneInput
|
|
30
|
+
include Base
|
|
31
|
+
include Base::Stringish
|
|
32
|
+
include Base::Placeholder
|
|
33
|
+
|
|
34
|
+
def to_html
|
|
35
|
+
input_wrapping do
|
|
36
|
+
label_html <<
|
|
37
|
+
builder.phone_field(method, input_html_options)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Formtastic
|
|
3
|
+
module Inputs
|
|
4
|
+
|
|
5
|
+
# A radio input is used to render a series of radio inputs. This is an alternative input choice
|
|
6
|
+
# for `belongs_to` associations like a `Post` belonging to a `Section` or an `Author`, or any
|
|
7
|
+
# case where the user needs to make a single selection from a pre-defined collectioon of choices.
|
|
8
|
+
#
|
|
9
|
+
# Within the standard `<li>` wrapper, the output is a `<fieldset>` with a `<legend>` to
|
|
10
|
+
# represent the "label" for the input, and an `<ol>` containing `<li>`s for each choice in
|
|
11
|
+
# the association. Each `<li>` choice has a `<label>` containing an `<input type="radio">` and
|
|
12
|
+
# the label text to describe each choice.
|
|
13
|
+
#
|
|
14
|
+
# Radio inputs can be considered as an alternative where a (non-multi) select input is used,
|
|
15
|
+
# especially in cases where there are only a few choices, however they are not used by default
|
|
16
|
+
# for any type of association or model attribute. You can choose to use a radio input instead of
|
|
17
|
+
# a select with `:as => :radio`.
|
|
18
|
+
#
|
|
19
|
+
# Like a select input, the flexibility of the `:collection` option (see examples) makes the
|
|
20
|
+
# :radio input viable as an alternative for many other input types. For example, instead of...
|
|
21
|
+
#
|
|
22
|
+
# * a `:string` input (where you want to force the user to choose from a few specific strings rather than entering anything)
|
|
23
|
+
# * a `:boolean` checkbox input (where the user could choose yes or no, rather than checking a box)
|
|
24
|
+
# * a `:date_select`, `:time_select` or `:datetime_select` input (where the user could choose from a small set of pre-determined dates)
|
|
25
|
+
# * a `:number` input (where the user could choose from a small set of pre-defined numbers)
|
|
26
|
+
# * a `:time_zone` input (where you want to provide your own small set of choices instead of relying on Rails)
|
|
27
|
+
# * a `:country` input (where you want to provide a small set of choices, no need for a plugin really)
|
|
28
|
+
#
|
|
29
|
+
# For radio inputs that map to associations on the object model, Formtastic will automatically
|
|
30
|
+
# load in a collection of objects on the association as options to choose from. This might be an
|
|
31
|
+
# `Author.all` on a `Post` form with an input for a `belongs_to :user` association, or a
|
|
32
|
+
# `Section.all` for a `Post` form with an input for a `belongs_to :section` association.
|
|
33
|
+
# You can override or customise this collection through the `:collection` option (see examples).
|
|
34
|
+
#
|
|
35
|
+
# For radio inputs that map to ActiveRecord `enum` attributes, Formtastic will automatically
|
|
36
|
+
# load in your enum options to be used as the radio button choices. This can be overridden with
|
|
37
|
+
# the `:collection` option, or augmented with I18n translations. See examples below.
|
|
38
|
+
#
|
|
39
|
+
# The way on which Formtastic renders the `value` attribute and label for each choice in the `:collection` is
|
|
40
|
+
# customisable (see examples below). When not provided, we fall back to a list of methods to try on each
|
|
41
|
+
# object such as `:to_label`, `:name` and `:to_s`, which are defined in the configurations
|
|
42
|
+
# `collection_label_methods` and `collection_value_methods`.
|
|
43
|
+
#
|
|
44
|
+
# @example Basic `belongs_to` example with full form context
|
|
45
|
+
#
|
|
46
|
+
# <%= semantic_form_for @post do |f| %>
|
|
47
|
+
# <%= f.inputs do %>
|
|
48
|
+
# <%= f.input :author, :as => :radio %>
|
|
49
|
+
# <% end %>
|
|
50
|
+
# <% end %>
|
|
51
|
+
#
|
|
52
|
+
# <form...>
|
|
53
|
+
# <fieldset>
|
|
54
|
+
# <ol>
|
|
55
|
+
# <li class='radio'>
|
|
56
|
+
# <fieldset>
|
|
57
|
+
# <legend class="label"><label>Categories</label></legend>
|
|
58
|
+
# <ol>
|
|
59
|
+
# <li>
|
|
60
|
+
# <label for="post_author_id_1">
|
|
61
|
+
# <input type="radio" id="post_author_id_1" value="1"> Justin
|
|
62
|
+
# </label>
|
|
63
|
+
# </li>
|
|
64
|
+
# <li>
|
|
65
|
+
# <label for="post_author_id_3">
|
|
66
|
+
# <input type="radio" id="post_author_id_3" value="3"> Kate
|
|
67
|
+
# </label>
|
|
68
|
+
# </li>
|
|
69
|
+
# <li>
|
|
70
|
+
# <label for="post_author_id_2">
|
|
71
|
+
# <input type="radio" id="post_author_id_2" value="2"> Amelia
|
|
72
|
+
# </label>
|
|
73
|
+
# </li>
|
|
74
|
+
# </ol>
|
|
75
|
+
# </fieldset>
|
|
76
|
+
# </li>
|
|
77
|
+
# </ol>
|
|
78
|
+
# </fieldset>
|
|
79
|
+
# </form>
|
|
80
|
+
#
|
|
81
|
+
# @example The `:collection` option can be used to customize the choices
|
|
82
|
+
# <%= f.input :author, :as => :radio, :collection => @authors %>
|
|
83
|
+
# <%= f.input :author, :as => :radio, :collection => Author.all %>
|
|
84
|
+
# <%= f.input :author, :as => :radio, :collection => Author.some_named_scope %>
|
|
85
|
+
# <%= f.input :author, :as => :radio, :collection => Author.pluck(:full_name, :id) %>
|
|
86
|
+
# <%= f.input :author, :as => :radio, :collection => Author.pluck(Arel.sql("CONCAT(`first_name`, ' ', `last_name`)"), :id)) %>
|
|
87
|
+
# <%= f.input :author, :as => :radio, :collection => [Author.find_by_login("justin"), Category.find_by_name("kate")] %>
|
|
88
|
+
# <%= f.input :author, :as => :radio, :collection => ["Justin", "Kate"] %>
|
|
89
|
+
# <%= f.input :author, :as => :radio, :collection => [["Justin", "justin"], ["Kate", "kate"]] %>
|
|
90
|
+
# <%= f.input :author, :as => :radio, :collection => [["Justin", "1"], ["Kate", "3"]] %>
|
|
91
|
+
# <%= f.input :author, :as => :radio, :collection => [["Justin", 1], ["Kate", 3]] %>
|
|
92
|
+
# <%= f.input :author, :as => :radio, :collection => [["Justin", :justin], ["Kate", :kate]] %>
|
|
93
|
+
# <%= f.input :author, :as => :radio, :collection => [:justin, :kate] %>
|
|
94
|
+
# <%= f.input :author, :as => :radio, :collection => 1..5 %>
|
|
95
|
+
#
|
|
96
|
+
# @example Set HTML attributes on each `<input type="radio">` tag with `:input_html`
|
|
97
|
+
# <%= f.input :author, :as => :radio, :input_html => { :size => 20, :multiple => true, :class => "special" } %>
|
|
98
|
+
#
|
|
99
|
+
# @example Set HTML attributes on the `<li>` wrapper with `:wrapper_html`
|
|
100
|
+
# <%= f.input :author, :as => :radio, :wrapper_html => { :class => "special" } %>
|
|
101
|
+
#
|
|
102
|
+
# @example `:value_as_class` can be used to add a class to the `<li>` wrapped around each choice using the radio value for custom styling of each choice
|
|
103
|
+
# <%= f.input :author, :as => :radio, :value_as_class => true %>
|
|
104
|
+
#
|
|
105
|
+
# @example Set HTML options on a specific radio input option with a 3rd element in the array for a collection member
|
|
106
|
+
# <%= f.input :author, :as => :radio, :collection => [["Test", 'test'], ["Try", "try", {:disabled => true}]]
|
|
107
|
+
#
|
|
108
|
+
# @example Using ActiveRecord enum attribute with i18n translation:
|
|
109
|
+
# # post.rb
|
|
110
|
+
# class Post < ActiveRecord::Base
|
|
111
|
+
# enum :status => [ :active, :archived ]
|
|
112
|
+
# end
|
|
113
|
+
# # en.yml
|
|
114
|
+
# en:
|
|
115
|
+
# activerecord:
|
|
116
|
+
# attributes:
|
|
117
|
+
# post:
|
|
118
|
+
# statuses:
|
|
119
|
+
# active: I am active!
|
|
120
|
+
# archived: I am archived!
|
|
121
|
+
# # form
|
|
122
|
+
# <%= f.input :status, :as => :radio %>
|
|
123
|
+
#
|
|
124
|
+
# @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
|
|
125
|
+
# @see Formtastic::Inputs::RadioInput as an alternative for `belongs_to` associations
|
|
126
|
+
#
|
|
127
|
+
# @todo :disabled like CheckBoxes?
|
|
128
|
+
class RadioInput
|
|
129
|
+
include Base
|
|
130
|
+
include Base::Collections
|
|
131
|
+
include Base::Choices
|
|
132
|
+
|
|
133
|
+
def to_html
|
|
134
|
+
input_wrapping do
|
|
135
|
+
choices_wrapping do
|
|
136
|
+
legend_html <<
|
|
137
|
+
choices_group_wrapping do
|
|
138
|
+
collection.map { |choice|
|
|
139
|
+
choice_wrapping(choice_wrapping_html_options(choice)) do
|
|
140
|
+
choice_html(choice)
|
|
141
|
+
end
|
|
142
|
+
}.join("\n").html_safe
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def choice_html(choice)
|
|
149
|
+
template.content_tag(:label,
|
|
150
|
+
builder.radio_button(input_name, choice_value(choice), input_html_options.merge(choice_html_options(choice)).merge(:required => false)) <<
|
|
151
|
+
choice_label(choice),
|
|
152
|
+
label_html_options.merge(:for => choice_input_dom_id(choice), :class => nil)
|
|
153
|
+
)
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# Override to remove the for attribute since this isn't associated with any element, as it's
|
|
157
|
+
# nested inside the legend.
|
|
158
|
+
def label_html_options
|
|
159
|
+
super.merge(:for => nil)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|