formtastic 1.2.5 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.yardopts +1 -0
- data/CHANGELOG +279 -0
- data/Gemfile +3 -0
- data/README.textile +155 -172
- data/RELEASE_PROCESS +7 -0
- data/Rakefile +52 -0
- data/app/assets/stylesheets/formtastic.css +275 -0
- data/app/assets/stylesheets/formtastic_ie6.css +27 -0
- data/app/assets/stylesheets/formtastic_ie7.css +17 -0
- data/formtastic.gemspec +51 -0
- data/lib/formtastic.rb +21 -1960
- data/lib/formtastic/engine.rb +7 -0
- data/lib/formtastic/form_builder.rb +83 -0
- data/lib/formtastic/helpers.rb +16 -0
- data/lib/formtastic/helpers/buttons_helper.rb +277 -0
- data/lib/formtastic/helpers/errors_helper.rb +113 -0
- data/lib/formtastic/helpers/fieldset_wrapper.rb +75 -0
- data/lib/formtastic/helpers/file_column_detection.rb +16 -0
- data/lib/formtastic/helpers/form_helper.rb +198 -0
- data/lib/formtastic/helpers/input_helper.rb +366 -0
- data/lib/formtastic/helpers/inputs_helper.rb +392 -0
- data/lib/formtastic/helpers/reflection.rb +33 -0
- data/lib/formtastic/helpers/semantic_form_helper.rb +11 -0
- data/lib/formtastic/html_attributes.rb +21 -0
- data/lib/formtastic/i18n.rb +1 -0
- data/lib/formtastic/inputs.rb +31 -0
- data/lib/formtastic/inputs/base.rb +61 -0
- data/lib/formtastic/inputs/base/associations.rb +31 -0
- data/lib/formtastic/inputs/base/choices.rb +103 -0
- data/lib/formtastic/inputs/base/collections.rb +94 -0
- data/lib/formtastic/inputs/base/database.rb +17 -0
- data/lib/formtastic/inputs/base/errors.rb +58 -0
- data/lib/formtastic/inputs/base/fileish.rb +23 -0
- data/lib/formtastic/inputs/base/grouped_collections.rb +77 -0
- data/lib/formtastic/inputs/base/hints.rb +31 -0
- data/lib/formtastic/inputs/base/html.rb +52 -0
- data/lib/formtastic/inputs/base/labelling.rb +55 -0
- data/lib/formtastic/inputs/base/naming.rb +42 -0
- data/lib/formtastic/inputs/base/options.rb +18 -0
- data/lib/formtastic/inputs/base/stringish.rb +35 -0
- data/lib/formtastic/inputs/base/timeish.rb +128 -0
- data/lib/formtastic/inputs/base/validations.rb +166 -0
- data/lib/formtastic/inputs/base/wrapping.rb +40 -0
- data/lib/formtastic/inputs/boolean_input.rb +96 -0
- data/lib/formtastic/inputs/check_boxes_input.rb +179 -0
- data/lib/formtastic/inputs/country_input.rb +66 -0
- data/lib/formtastic/inputs/date_input.rb +14 -0
- data/lib/formtastic/inputs/datetime_input.rb +9 -0
- data/lib/formtastic/inputs/email_input.rb +40 -0
- data/lib/formtastic/inputs/file_input.rb +42 -0
- data/lib/formtastic/inputs/hidden_input.rb +66 -0
- data/lib/formtastic/inputs/number_input.rb +118 -0
- data/lib/formtastic/inputs/numeric_input.rb +21 -0
- data/lib/formtastic/inputs/password_input.rb +40 -0
- data/lib/formtastic/inputs/phone_input.rb +41 -0
- data/lib/formtastic/inputs/radio_input.rb +157 -0
- data/lib/formtastic/inputs/range_input.rb +119 -0
- data/lib/formtastic/inputs/search_input.rb +40 -0
- data/lib/formtastic/inputs/select_input.rb +210 -0
- data/lib/formtastic/inputs/string_input.rb +34 -0
- data/lib/formtastic/inputs/text_input.rb +47 -0
- data/lib/formtastic/inputs/time_input.rb +14 -0
- data/lib/formtastic/inputs/time_zone_input.rb +48 -0
- data/lib/formtastic/inputs/url_input.rb +40 -0
- data/lib/formtastic/localized_string.rb +105 -0
- data/lib/formtastic/railtie.rb +5 -7
- data/lib/formtastic/semantic_form_builder.rb +11 -0
- data/lib/formtastic/util.rb +6 -19
- data/lib/formtastic/version.rb +3 -0
- data/lib/generators/formtastic/install/install_generator.rb +28 -6
- data/lib/generators/templates/_form.html.erb +10 -4
- data/lib/generators/templates/_form.html.haml +8 -4
- data/lib/generators/templates/formtastic.rb +25 -32
- data/lib/locale/en.yml +1 -0
- data/lib/tasks/verify_rcov.rb +44 -0
- data/sample/basic_inputs.html +182 -0
- data/sample/config.ru +69 -0
- data/sample/index.html +14 -0
- data/spec/builder/custom_builder_spec.rb +109 -0
- data/spec/builder/error_proc_spec.rb +27 -0
- data/spec/builder/errors_spec.rb +193 -0
- data/spec/builder/semantic_fields_for_spec.rb +88 -0
- data/spec/helpers/buttons_helper_spec.rb +150 -0
- data/spec/helpers/commit_button_helper_spec.rb +470 -0
- data/spec/helpers/form_helper_spec.rb +135 -0
- data/spec/helpers/input_helper_spec.rb +837 -0
- data/spec/helpers/inputs_helper_spec.rb +562 -0
- data/spec/helpers/semantic_errors_helper_spec.rb +112 -0
- data/spec/i18n_spec.rb +199 -0
- data/spec/inputs/boolean_input_spec.rb +184 -0
- data/spec/inputs/check_boxes_input_spec.rb +375 -0
- data/spec/inputs/country_input_spec.rb +133 -0
- data/spec/inputs/custom_input_spec.rb +52 -0
- data/spec/inputs/date_input_spec.rb +110 -0
- data/spec/inputs/datetime_input_spec.rb +115 -0
- data/spec/inputs/email_input_spec.rb +55 -0
- data/spec/inputs/file_input_spec.rb +59 -0
- data/spec/inputs/hidden_input_spec.rb +120 -0
- data/spec/inputs/include_blank_spec.rb +70 -0
- data/spec/inputs/label_spec.rb +104 -0
- data/spec/inputs/number_input_spec.rb +487 -0
- data/spec/inputs/numeric_input_spec.rb +41 -0
- data/spec/inputs/password_input_spec.rb +69 -0
- data/spec/inputs/phone_input_spec.rb +55 -0
- data/spec/inputs/placeholder_spec.rb +71 -0
- data/spec/inputs/radio_input_spec.rb +234 -0
- data/spec/inputs/range_input_spec.rb +477 -0
- data/spec/inputs/search_input_spec.rb +55 -0
- data/spec/inputs/select_input_spec.rb +545 -0
- data/spec/inputs/string_input_spec.rb +163 -0
- data/spec/inputs/text_input_spec.rb +158 -0
- data/spec/inputs/time_input_spec.rb +155 -0
- data/spec/inputs/time_zone_input_spec.rb +87 -0
- data/spec/inputs/url_input_spec.rb +55 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +361 -0
- data/spec/support/custom_macros.rb +656 -0
- data/spec/support/deferred_garbage_collection.rb +21 -0
- data/spec/support/deprecation.rb +6 -0
- data/spec/support/test_environment.rb +30 -0
- metadata +306 -88
- 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/generators/formtastic/form/form_generator.rb +0 -84
- 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
data/.gitignore
ADDED
data/.rspec
ADDED
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--no-private --title "Formtastic Documentation" --markup markdown --quiet
|
data/CHANGELOG
ADDED
@@ -0,0 +1,279 @@
|
|
1
|
+
2.0.0.rc1
|
2
|
+
|
3
|
+
* Removed the "inline_order" configuration (redefine input_wrapping instead)
|
4
|
+
* Removed the "special" implementation of label() from FormBuilder, so builder.label will call Rails' label helper, not ours
|
5
|
+
* Changed the HTML id attribute used for hidden inputs to be consistent with all other inputs
|
6
|
+
* Changed formtastic:form generator include the wrapping semantic_form_for block
|
7
|
+
* Changed formtastic:form generator to generate a partial by default (instead of copying to clipboard, which can be done with --copy)
|
8
|
+
* Removed formtastic_stylesheet_link_tag
|
9
|
+
* Improved some documentation, much more to come
|
10
|
+
* Tagged many modules as @private to remove from YARD documentation
|
11
|
+
* Added YARD as development dependency for a massive documentation effort
|
12
|
+
* Renamed Formtastic::SemanticFormHelper to Formtastic::Helpers::FormHelper (SemanticFormHelper still exists as a module which includes the new module, need to handle deprecation notices somehow)
|
13
|
+
* Renamed Formtastic::SemanticFormBuilder to Formtastic::FormBuilder (SemanticFormBuilder still exists as a subclass, need to handle deprecation notices somehow)
|
14
|
+
* Massive refactoring of formtastic.rb into around 30 files and modules like StringInput and ButtonsHelper
|
15
|
+
* Removed chunks of Rails 2 specific code, tests and documentation
|
16
|
+
* Added support for HTML5 required attribute on input, select and textarea tags
|
17
|
+
* Added support for HTML5 min/max/step attributes on NumericInput
|
18
|
+
* Added support for HTML5 placeholder attributes on Stringish inputs (string, email, phone, url, search, number, password)
|
19
|
+
* Added support for HTML5 autofocus attributes
|
20
|
+
* Changed nested inputs() blocks to be automatically wrapped in an `<li>` tag to preserve HTML validity
|
21
|
+
* Changed quick forms to skip polymorphic associations (they didn't work)
|
22
|
+
* Changed short hand forms to raise an error when trying to render an input for a polymorphic association (it didn't work, need a collection)
|
23
|
+
* Changed input() to raise an error when a :collection is not provided for a polymorphic association (we can't guess which class to use)
|
24
|
+
* Removed semantic_remote_form_for etc, the remote_form_for helpers don't exist in Rails 3
|
25
|
+
* Changed :label_method option to :member_label (with backwards compat and deprecation warnings)
|
26
|
+
* Changed :value_method option to :member_value (with backwards compat and deprecation warnings)
|
27
|
+
* Changed :grouped_label_method option to :grouped_label (with backwards compat and deprecation warnings)
|
28
|
+
* Added support for a Method objects to :member_label/:member_value (aka :label_method/:value_method)
|
29
|
+
* Improved support for Mongoid
|
30
|
+
* Changed Rails dependency from ~> 3.0.0 to ~> 3.0 to allow experimentation with Rails 3.1 betas
|
31
|
+
* Removed some overly eager CSS resets on form elements that made Opera and FF inputs look pretty ugly
|
32
|
+
* Removed specificity and duplication in CSS
|
33
|
+
* Added many new classes to DOM elements to enable more efficient and descriptive CSS
|
34
|
+
* Improved visual/spacing consistency in checkboxes
|
35
|
+
* Added non-standard zoom:1; to clearfixes to support IE better
|
36
|
+
* Changed CSS coding style to multi-line so we can annotate the styles better
|
37
|
+
* Fixed that overly specific CSS rules weren't applied to nested form elements properly
|
38
|
+
* Removed formtastic:form generator and changed formtastic:install generator
|
39
|
+
to override scaffold generator
|
40
|
+
* Refactored and consolidated CSS by adding extra class names into the mark-up, preferring to style by class instead of element wherever possible
|
41
|
+
* Added IE6 and IE7 stylesheets for specific fixes if needed (uncomplicates formtastic.css)
|
42
|
+
* Added support for Rails 3.1 asset pipeline as well as previous generated CSS for Rails < 3.1
|
43
|
+
* Made many subtle visual improvements to CSS, especially in IE
|
44
|
+
|
45
|
+
1.2.4
|
46
|
+
|
47
|
+
* no changes
|
48
|
+
|
49
|
+
1.2.4.beta2
|
50
|
+
|
51
|
+
* Changed :boolean inputs to use Rails' check_box_checked? instead of our own logic
|
52
|
+
* Changed developer instructions in README
|
53
|
+
* Fixed :boolean inputs to disable the included hidden input when disabling the actual checkbox
|
54
|
+
* Fixed that Formtastic was making changes to the options hash directly instead of on a duplicate, causing problems for those trying to reuse options on multiple inputs in the view
|
55
|
+
* Fixed that tiny scroll bars were appearing on legends in date/time/radio/cbheckboxes fielsets (GH-477)
|
56
|
+
* Fixed an issue when formtastic fails to determine if a checkbox is checked with custom checked and unchecked values (thanks to Eugene Bolshakov)
|
57
|
+
* Fixed that the hidden input rendered with a boolean checkbox did nt use the custom :name from :input_html options hash
|
58
|
+
* Fixed issue where Firefox 4 gives focus to the <li> wrapper (fixes #524).
|
59
|
+
* Fixed that a shared input options hash could not be re-used in the view without being altered by each input
|
60
|
+
* Improved compatibility with Mongoid Documents
|
61
|
+
* Updated i18n dependency to ~> 0.4
|
62
|
+
|
63
|
+
1.2.4.beta
|
64
|
+
|
65
|
+
* Changed :boolean inputs to use Rails' check_box_checked? instead of our own logic
|
66
|
+
* Changed developer instructions in README
|
67
|
+
* Fixed :boolean inputs to disable the included hidden input when disabling the actual checkbox
|
68
|
+
* Fixed that Formtastic was making changes to the options hash directly instead of on a duplicate, causing problems for those trying to reuse options on multiple inputs in the view
|
69
|
+
* Fixed that tiny scroll bars were appearing on legends in date/time/radio/cbheckboxes fielsets (GH-477)
|
70
|
+
* Fixed an issue when formtastic fails to determine if a checkbox is checked with custom checked and unchecked values (thanks to Eugene Bolshakov)
|
71
|
+
* Fixed that the hidden input rendered with a boolean checkbox did nt use the custom :name from :input_html options hash
|
72
|
+
|
73
|
+
1.2.3
|
74
|
+
|
75
|
+
* Removed deprecated methods input_field_set, button_field_set, boolean_select_input, boolean_radio_input and boolean_radio_input
|
76
|
+
* Removed deprecated :class option on commit_button (use :input_html instead)
|
77
|
+
* Fixed that stylesheets and initializers directories would be removed on uninstalling
|
78
|
+
* Fixed some documentation and formatting
|
79
|
+
* Fixed test coverage issues under Ruby 192 and Rails 2
|
80
|
+
* Fixed that input_html options were not being passed down to checkbox tags
|
81
|
+
* Changed internal duplication of the options hash so that the same options hash can be re-used over multiple inputs without being altered
|
82
|
+
* Changed internal configuration to use class_attribute when available (Rails 3) to avoid deprecation warnings
|
83
|
+
* Added Rails 3 compatible form generator templates in addition to existing Rails 2 support
|
84
|
+
* Added reflection on allow_blank option when determining the 'required' status of an input
|
85
|
+
|
86
|
+
|
87
|
+
1.2.2
|
88
|
+
|
89
|
+
* Removed deprecated aliased input names (:as => :boolean_select, :as => :boolean_radio_input
|
90
|
+
* Removed deprecated aliased method names (input_field_set, button_field_set)
|
91
|
+
* Removed deprecated :class => 'whatever' on commit_button
|
92
|
+
* Fixed that classes in :button_html were being merged into :wrapper_html
|
93
|
+
* Fixed that :include_blank was being ignored (always false) for multi selects
|
94
|
+
* Fixed that we should reflect on allow_blank option to determine required status with validates_inclusion_of
|
95
|
+
* Added the ability to pass :input_html options be passed to the checkbox on a boolean input
|
96
|
+
* Developers: Added bundler support to for developer/contribution
|
97
|
+
* Developers: Fixed spec coverage under Rails 2 and Ruby 1.9.2
|
98
|
+
|
99
|
+
1.2.1
|
100
|
+
|
101
|
+
* test suite compatibilities with Rails 3.0.3
|
102
|
+
|
103
|
+
1.2.1.beta3
|
104
|
+
|
105
|
+
* Fixed bad merge related to :boolean inputs in 1.2.1.beta
|
106
|
+
|
107
|
+
1.2.1.beta2
|
108
|
+
|
109
|
+
* Fixed typos in gemspec post-install message
|
110
|
+
|
111
|
+
1.2.1.beta
|
112
|
+
|
113
|
+
* Fixed that unchecking :boolean inputs would not send the correct params (and not persist the change the the DB)
|
114
|
+
* Fixed that :boolean inputs checked state was not reflecting the database/model value
|
115
|
+
* Fixed that init.rb and rails/init.rb were not included in the gem (affecting Rails 2)
|
116
|
+
|
117
|
+
1.2.0
|
118
|
+
|
119
|
+
* Changed default_text_area_width to nil, overlooked in recent CSS/width changes
|
120
|
+
* Improved documentation
|
121
|
+
|
122
|
+
1.2.0.beta2
|
123
|
+
|
124
|
+
* Added :wrapper_html functionality to commit_button() to match what input() does
|
125
|
+
* Deprecated the :class option on commit_button(), use :wrapper_html instead
|
126
|
+
* Added hpricot as missing development dependency
|
127
|
+
* Improved documentation
|
128
|
+
|
129
|
+
1.2.0.beta
|
130
|
+
|
131
|
+
* New Stuff
|
132
|
+
|
133
|
+
* Added support for Paperclip's questionable use of multiple error keys on a single attribute, so errors on Paperclip :file inputs Just Work
|
134
|
+
* Added ability for the error and hint class to be overridden with :hint_class and :error_class, and configurable defaults app-wide
|
135
|
+
* Added basic support for multiple forms in the same document by allowing the element ids to be prefixed with the :namespace option on semantic_form_for
|
136
|
+
* Added a fallback to Rails' helpers.label key if Formtastic label translation are not found
|
137
|
+
* Added support for default_text_area_width
|
138
|
+
* Added support for #persisted? over #new_record? (ActiveModel)
|
139
|
+
* Added the 'required' logic to attributes with validates_inclusion_of validation, in addition to validates_presence_of
|
140
|
+
* Added new HTML5 :as => :email input (Rails 3)
|
141
|
+
* Added new HTML5 :as => :phone input (Rails 3)
|
142
|
+
* Added new HTML5 :as => :search input (Rails 3)
|
143
|
+
* Added new HTML5 :as => :url input (Rails 3)
|
144
|
+
* Added the ability for the :collection option to accept a string of HTML (like the output from grouped_options_for_select), rather than just Arrays, Hashes, collections, etc.
|
145
|
+
* Added the ability to set your own form class, instead of 'formtastic'
|
146
|
+
* Added maxlength attributes to inputs if it can be determined via the ValidationReflection plugin or ActiveModel validation reflections
|
147
|
+
* Added the ability to override the form class (Post => "post") through an :as option on semantic_form_for option
|
148
|
+
* Added the ability to customize the order for specific types of inputs. This is configured on a type basis and if a type is not found it willfall back to the default order as defined by @@inline_order
|
149
|
+
* Added :first as a new rendering choice for the errors on each input
|
150
|
+
* Added custom_inline_order to allow inline ordering per input type
|
151
|
+
* Added the ability to override the generator templates in Rails 3
|
152
|
+
|
153
|
+
* Fixes
|
154
|
+
|
155
|
+
* Fixed invalid HTML generated by Rails' hidden inputs on checkboxes (by rendering our own hidden tag in a more deliberate place)
|
156
|
+
* Fixed a bunch of invalid i18n key defaults
|
157
|
+
* Fixed that 'required' classes and logic were not being applied to :check_boxes and :radio inputs
|
158
|
+
* Fixed CSS bugs around Firefox's quirks with form elements that resulted in overflow/scroll bar issues
|
159
|
+
* Fixed that errors on fields with association were not marking the wrapping tag with the error class
|
160
|
+
* Fixed CSS where FF was displaying extra scroll bars on .check_boxes and .radio inputs (and the choices within them)
|
161
|
+
|
162
|
+
* Changes
|
163
|
+
|
164
|
+
* Changed that we were defaulting to a :select input for columns ending in _id, instead of columns with an appropriate associations
|
165
|
+
* Deprecated a bunch of aliased method names that should no longer be used
|
166
|
+
* Removed deprecated :selected, :checked and :default options
|
167
|
+
* Changed the width styling for string, numeric, password and other basic inputs, defaults to 75% unless the size attribute is present
|
168
|
+
* Changed string, numeric, password and other basic inputs' default text field size config to nil instead of 50, meaning the size attribute will be ommitted from most inputs, makeing styling easier, and custom sizes with the size attribute more deliberate
|
169
|
+
* Changed string, numeric, password and other basic inputs to no longer add the size attribute based on column information (the default config is applied, unless it's nil)
|
170
|
+
* Changed text input css behaviour updated to be similar to string etc
|
171
|
+
* Changed text inputs to no longer include a default cols attribute, specify it with :input_html if you need it, but the value we were using was useless... also beefed up spec coverage
|
172
|
+
* Removed :label calls from the generated ERB in the form generator (i18n is preferred)
|
173
|
+
* Changed that :select inputs for HABTM associations would ignore the :include_blank option
|
174
|
+
* Changed the default method on collections from Model.find(:all) to Model.all
|
175
|
+
* Removed the deprecated formtastic_stylesheets generator
|
176
|
+
* Changed the minimum Rails version to 2.3.7, which the earliest version which the specs pass with
|
177
|
+
* Changed :password inputs to be sized by percentage (like other string-ish inputs), rather then em-based
|
178
|
+
|
179
|
+
1.1.0
|
180
|
+
|
181
|
+
* documentation changes only
|
182
|
+
|
183
|
+
1.1.0.beta [Specs passed against Rails 2.3.8, 3.0.0.rc & 3.0.0]
|
184
|
+
|
185
|
+
* Changed semantic_remote_form_for to allow for unobstrusive javascript / :remote option (rails3)
|
186
|
+
* Changed spec_helper to support Rails 2 with RSpec or Rails 3 with RSpec 2 environments
|
187
|
+
* Changed Rakefile to initalize the correct testing framework for the enviroment
|
188
|
+
* Changed i18n dependency to >= 0.4
|
189
|
+
* Fixed use of model_name.human instead of model_name.human_name (rails3)
|
190
|
+
* Fixed use of deprecated Errors#on_base
|
191
|
+
* Fixed use of ActionController::RecordIdentifier#singular_class_name (rails3)
|
192
|
+
* Added railtie to perform initialization tasks after the rails framework is available (rails3)
|
193
|
+
* Added compatible install and form helpers (rails3)
|
194
|
+
* Added support for ActiveModel Validations, thanks to Guillaume Belleguic (rails3)
|
195
|
+
|
196
|
+
1.0.1
|
197
|
+
|
198
|
+
* fixed "already initialised constant" warnings on boot
|
199
|
+
|
200
|
+
1.0.0
|
201
|
+
|
202
|
+
* nothing changed from rc2
|
203
|
+
|
204
|
+
1.0.0.rc2
|
205
|
+
|
206
|
+
* Fixed that :label=>false didn't disable the label on checkboxes/radiobuttons (#331)
|
207
|
+
* Added full support of :input_html options for hidden fields
|
208
|
+
|
209
|
+
1.0.0.rc
|
210
|
+
|
211
|
+
* Fixed that :checked_value and :unchecked_value options were being passed down into the HTML tags as attributes
|
212
|
+
|
213
|
+
1.0.0.beta4
|
214
|
+
|
215
|
+
* ensure i18n < 0.4 is listed as a dependency in the gemspec
|
216
|
+
|
217
|
+
1.0.0.beta3
|
218
|
+
|
219
|
+
* Added :ignore_date option to time inputs (#308)
|
220
|
+
* Fixed inputs_for_nested_attributes returning out of the proc on has_many associated nested models.
|
221
|
+
* Fixed with_custom_field_error_proc to use ensure for restoring default field_error_proc and to store it in a local variable instead of in a class variable (nested calls were problematic due to the globalness of class variables)
|
222
|
+
|
223
|
+
1.0.0.beta2
|
224
|
+
|
225
|
+
* Added default escaping of html entities in labels and hints (#292, #299)
|
226
|
+
* Added/Fixed that :value_method and :label_method were not being used for simple collections (like Arrays)
|
227
|
+
* Added some more compatibility for Mongooid and other ORMs by checking for reflection information before calling it
|
228
|
+
* Fixed deprecation warnings in Rails 2.3.6 and newer
|
229
|
+
* Fixed a bug where :check_boxes and :radio were using method instead of :label option
|
230
|
+
* Fixed a conflict where i18n lookups were failing when an attribute and model have the same name
|
231
|
+
* Fixed some html that was not marked as safe
|
232
|
+
|
233
|
+
1.0.0.beta
|
234
|
+
|
235
|
+
* Fixed :radio and :check_boxes inputs so that the legend no longer includes a <label> with a `for` attribute pointing to an input that doesn't exist (#253)
|
236
|
+
* Fixed that some inputs had invalid 'find_options' attribute (#262)
|
237
|
+
* Fixed that we were calling html_safe! when it was not always available
|
238
|
+
* Added the ability for :input_html to now accept an option of :size => nil, to exclude the :size attribute altogether (#267)
|
239
|
+
|
240
|
+
0.9.10
|
241
|
+
|
242
|
+
* Fixed i18n incompatibility with Rails 2.3.8 by reverting two i18n patches pulled in from the rails3 branch
|
243
|
+
|
244
|
+
0.9.9
|
245
|
+
|
246
|
+
* Changed date/time inputs to default to nil instead of Time.now when the object has no value (due to deprecation warning, #240)
|
247
|
+
* Changed the behaviour of associations with a :class_name option to be more consistent with what Rails expects
|
248
|
+
* Fixed issues relating to Rails 2.3.6 automatically escaping ERB
|
249
|
+
* Fixed issues with Ruby 1.9.1 and Haml
|
250
|
+
* Fixed use of deprecated {{key}} syntax in i18n interpolation (thanks to Hans Petter Wilhelmsen)
|
251
|
+
* Added the :disabled option to check_boxes input
|
252
|
+
* Added translation support for nested models (thanks to Toni Tuominen)
|
253
|
+
|
254
|
+
0.9.8
|
255
|
+
|
256
|
+
* Deprecated :selected/:checked options, see http://wiki.github.com/justinfrench/formtastic/deprecation-of-selected-option
|
257
|
+
* Changed CSS rules for fieldset lists to be more specific
|
258
|
+
* Changed that radio and checkbox inputs used to associate the legend label with the first choice's input (#101)
|
259
|
+
* Changed the generators to use |f| rather than |form| (#151)
|
260
|
+
* Changed the behaviour of :selected/:checked options to address several bugs and inconsistencies (#152)
|
261
|
+
* Changed CSS for input width property to max-width, allowing a size attribute to still be set
|
262
|
+
* Fixed an issue where label_str_method not honoured if the object is an ActiveRecord object
|
263
|
+
* Fixed incorrect html class for namespaced objects ("/" replaced with "_")
|
264
|
+
* Fixed compatibility issue with SearchLogic (#155)
|
265
|
+
* Fixed an issue where label_str_method was not being overridden with i18n
|
266
|
+
* Fixed a button text issue with Rails 2.x in which human_name on multi-word models returned one word (eg Ticketrequest) (#153)
|
267
|
+
* Fixed the behaviour of select inputs when the belongs_to or has_many association has a special :class_name option
|
268
|
+
* Fixed line numbers from eval'd code, to help when debugging
|
269
|
+
* Fixed CSS issue that hidden fields were not always hidden (Chrome for example) (#209)
|
270
|
+
* Fixed and improved CSS with nested fieldsets and legends
|
271
|
+
* Fixed date/time inputs where :include_seconds => true
|
272
|
+
* Fixed that inline hints were still being rendered on hidden inputs
|
273
|
+
* Fixed broken CSS declaration missing a colon
|
274
|
+
* Added configuration preferences for row and column attributes on textareas
|
275
|
+
* Added semantic_errors helper and CSS (for all errors on an object)
|
276
|
+
* Added :filename to the list of @@file_methods, to support carrierwave plugin (#156)
|
277
|
+
* Added a Formtastic::LayoutHelper with formtastic_stylesheets helper method for linking to all Formtastic CSS files
|
278
|
+
* Added labels option to date/time/datetime fields to customise the label of each part of the set (year, month, etc)
|
279
|
+
* Added many improvements to the README and docs
|
data/Gemfile
ADDED
data/README.textile
CHANGED
@@ -4,14 +4,23 @@ Formtastic is a Rails FormBuilder DSL (with some other goodies) to make it far e
|
|
4
4
|
|
5
5
|
<a href='http://www.pledgie.com/campaigns/2178'><img alt='Click here to lend your support to: formtastic and make a donation at www.pledgie.com !' src='http://pledgie.com/campaigns/2178.png?skin_name=chrome' border='0' /></a>
|
6
6
|
|
7
|
+
|
8
|
+
h2. Compatibility
|
9
|
+
|
10
|
+
* Formtastic 1.x is compatible with both Rails 2 and 3, and is being maintained for bug fixes in the the "1.2-stable branch":https://github.com/justinfrench/formtastic/tree/1.2-stable.
|
11
|
+
* Formtastic 2.0 will be Rails 3.x compatible only
|
12
|
+
* If you're bundling Formtastic from edge/master, get ready for a bumpy ride. Try the "1.2-stable branch":https://github.com/justinfrench/formtastic/tree/1.2-stable.
|
13
|
+
* Formtastic, much like Rails, is very ActiveRecord-centric. Many are successfully using other ActiveModel-like ORMs and objects (DataMapper, MongoMapper, Mongoid, Authlogic, Devise...) but we're not guaranteeing full compatibility at this stage. Patches are welcome!
|
14
|
+
|
15
|
+
|
7
16
|
h2. The Story
|
8
17
|
|
9
18
|
One day, I finally had enough, so I opened up my text editor, and wrote a DSL for how I'd like to author forms:
|
10
19
|
|
11
20
|
<pre>
|
12
|
-
|
21
|
+
<%= semantic_form_for @article do |form| %>
|
13
22
|
|
14
|
-
|
23
|
+
<%= form.inputs :name => "Basic" do %>
|
15
24
|
<%= form.input :title %>
|
16
25
|
<%= form.input :body %>
|
17
26
|
<%= form.input :section %>
|
@@ -20,19 +29,19 @@ One day, I finally had enough, so I opened up my text editor, and wrote a DSL fo
|
|
20
29
|
<%= form.input :allow_comments, :label => "Allow commenting on this article" %>
|
21
30
|
<% end %>
|
22
31
|
|
23
|
-
|
32
|
+
<%= form.inputs :name => "Advanced" do %>
|
24
33
|
<%= form.input :keywords, :required => false, :hint => "Example: ruby, rails, forms" %>
|
25
34
|
<%= form.input :extract, :required => false %>
|
26
35
|
<%= form.input :description, :required => false %>
|
27
36
|
<%= form.input :url_title, :required => false %>
|
28
37
|
<% end %>
|
29
38
|
|
30
|
-
|
39
|
+
<%= form.inputs :name => "Author", :for => :author do |author_form| %>
|
31
40
|
<%= author_form.input :first_name %>
|
32
41
|
<%= author_form.input :last_name %>
|
33
42
|
<% end %>
|
34
43
|
|
35
|
-
|
44
|
+
<%= form.buttons do %>
|
36
45
|
<%= form.commit_button %>
|
37
46
|
<% end %>
|
38
47
|
|
@@ -46,7 +55,7 @@ h2. It's better than _SomeOtherFormBuilder_ because...
|
|
46
55
|
|
47
56
|
* it can handle @belongs_to@ associations (like Post belongs_to :author), rendering a select or set of radio inputs with choices from the parent model.
|
48
57
|
* it can handle @has_many@ and @has_and_belongs_to_many@ associations (like: Post has_many :tags), rendering a multi-select with choices from the child models.
|
49
|
-
* it's Rails
|
58
|
+
* it's Rails 3 compatible (including nested forms).
|
50
59
|
* it has internationalization (I18n)!
|
51
60
|
* it's _really_ quick to get started with a basic form in place (4 lines), then go back to add in more detail if you need it.
|
52
61
|
* there's heaps of elements, id and class attributes for you to hook in your CSS and JS.
|
@@ -54,6 +63,7 @@ h2. It's better than _SomeOtherFormBuilder_ because...
|
|
54
63
|
* it doesn't hijack or change any of the standard Rails form inputs, so you can still use them as expected (even mix and match).
|
55
64
|
* it's got absolutely awesome spec coverage.
|
56
65
|
* there's a bunch of people using and working on it (it's not just one developer building half a solution).
|
66
|
+
* it has growing HTML5 support (new inputs like email/phone/search, new attributes like required/min/max/step/placeholder)
|
57
67
|
|
58
68
|
|
59
69
|
h2. Why?
|
@@ -81,63 +91,65 @@ RDoc documentation _should_ be automatically generated after each commit and mad
|
|
81
91
|
|
82
92
|
h2. Installation
|
83
93
|
|
84
|
-
|
94
|
+
Simply add Formtastic to your Gemfile and bundle it up:
|
85
95
|
|
86
|
-
|
96
|
+
<pre>
|
97
|
+
gem 'formtastic', '~> 1.2.3'
|
98
|
+
</pre>
|
87
99
|
|
88
|
-
|
100
|
+
If you want to try out our work towards Formtastic 2.0 (Rails >= 3 only), bundle in Formtastic directly from Github with the @:git@ option instead:
|
89
101
|
|
90
102
|
<pre>
|
91
|
-
gem 'formtastic', '
|
103
|
+
gem 'formtastic', :git => 'http://github.com/justinfrench/formtastic', :branch => 'master'
|
92
104
|
</pre>
|
93
105
|
|
94
|
-
Optionally, run the generator to copy
|
106
|
+
Optionally, run the generator to copy a stylesheet (Rails 3.0.x only) and a configuration initializer into your application:
|
95
107
|
|
96
108
|
<pre>
|
97
|
-
# Rails 3:
|
98
109
|
$ rails generate formtastic:install
|
99
|
-
|
100
|
-
# Or Rails 2:
|
101
|
-
$ ./script/generate formtastic
|
102
110
|
</pre>
|
103
111
|
|
104
112
|
|
105
113
|
h2. Stylesheets
|
106
114
|
|
107
|
-
A proof-of-concept
|
115
|
+
A proof-of-concept set of stylesheets are provided which you can include in your layout. Customization is best achieved by overriding these styles in an additional stylesheet.
|
116
|
+
|
117
|
+
h3. Stylesheet usage in Rails < 3.1:
|
108
118
|
|
109
119
|
<pre>
|
110
|
-
|
111
|
-
...
|
112
|
-
<%= formtastic_stylesheet_link_tag %>
|
113
|
-
...
|
114
|
-
</head>
|
120
|
+
$ rails generate formtastic:install
|
115
121
|
</pre>
|
116
122
|
|
123
|
+
<pre>
|
124
|
+
# app/views/layouts/application.html.erb
|
125
|
+
<%= stylesheet_link_tag 'formtastic', 'my_formtastic_changes' %>
|
126
|
+
<!--[if IE 6]><%= stylesheet_link_tag 'formtastic_ie6' %><![endif]-->
|
127
|
+
<!--[if IE 7]><%= stylesheet_link_tag 'formtastic_ie7' %><![endif]-->
|
128
|
+
</pre>
|
117
129
|
|
118
|
-
|
119
|
-
|
120
|
-
*Please note:* Formtastic makes use of a lot of ERB blocks and currently supports both Rails 2 and Rails 3, which means the syntax in these examples will differ depending on which version of Rails you're using.
|
130
|
+
h3. Stylesheet usage in Rails >= 3.1:
|
121
131
|
|
122
|
-
|
132
|
+
Rails 3.1 introduces an asset pipeline that allows plugins like Formtastic to serve their own Stylesheets, Javascripts, etc without having to run generators that copy them accross to the host application. Formtastic makes three stylesheets available as an Engine, you just need to require them in your global stylesheets.
|
123
133
|
|
124
134
|
<pre>
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
...
|
129
|
-
<% end %>
|
130
|
-
<% end %>
|
135
|
+
# app/assets/stylesheets/application.css
|
136
|
+
*= require formtastic
|
137
|
+
*= require my_formtastic_changes
|
131
138
|
|
132
|
-
|
133
|
-
|
134
|
-
<%= form.inputs do %>
|
135
|
-
...
|
136
|
-
<% end %>
|
137
|
-
<% end %>
|
138
|
-
</pre>
|
139
|
+
# app/assets/stylesheets/ie6.css
|
140
|
+
*= require formtastic_ie6
|
139
141
|
|
140
|
-
|
142
|
+
# app/assets/stylesheets/ie7.css
|
143
|
+
*= require formtastic_ie7
|
144
|
+
</pre>
|
145
|
+
|
146
|
+
<pre>
|
147
|
+
# app/views/layouts/application.html.erb
|
148
|
+
<%= stylesheet_link_tag 'application' %>
|
149
|
+
<!--[if IE 6]><%= stylesheet_link_tag 'ie6' %><![endif]-->
|
150
|
+
<!--[if IE 7]><%= stylesheet_link_tag 'ie7' %><![endif]-->
|
151
|
+
</pre>
|
152
|
+
|
141
153
|
|
142
154
|
|
143
155
|
h2. Usage
|
@@ -147,7 +159,7 @@ Forms are really boring to code... you want to get onto the good stuff as fast a
|
|
147
159
|
This renders a set of inputs (one for _most_ columns in the database table, and one for each ActiveRecord @belongs_to@-association), followed by a submit button:
|
148
160
|
|
149
161
|
<pre>
|
150
|
-
|
162
|
+
<%= semantic_form_for @user do |form| %>
|
151
163
|
<%= form.inputs %>
|
152
164
|
<%= form.buttons %>
|
153
165
|
<% end %>
|
@@ -158,7 +170,7 @@ This is a great way to get something up fast, but like scaffolding, it's not rec
|
|
158
170
|
You probably want to specify the order of the fields, skip some of the fields or even add in fields that Formtastic couldn't detect, you can pass in a list of field names to @inputs@ and list of button names to @buttons@:
|
159
171
|
|
160
172
|
<pre>
|
161
|
-
|
173
|
+
<%= semantic_form_for @user do |form| %>
|
162
174
|
<%= form.inputs :title, :body, :section, :categories, :created_at %>
|
163
175
|
<%= form.buttons :commit %>
|
164
176
|
<% end %>
|
@@ -167,15 +179,15 @@ You probably want to specify the order of the fields, skip some of the fields or
|
|
167
179
|
You probably want control over the input type Formtastic uses for each field, you can expand the @inputs@ and @buttons@ blocks. This specifies the @:section@ input should be a set of radio buttons (rather than the default select box), and that the @:created_at@ field should be a string (rather than the default datetime selects):
|
168
180
|
|
169
181
|
<pre>
|
170
|
-
|
171
|
-
|
182
|
+
<%= semantic_form_for @post do |form| %>
|
183
|
+
<%= form.inputs do %>
|
172
184
|
<%= form.input :title %>
|
173
185
|
<%= form.input :body %>
|
174
186
|
<%= form.input :section, :as => :radio %>
|
175
187
|
<%= form.input :categories %>
|
176
188
|
<%= form.input :created_at, :as => :string %>
|
177
189
|
<% end %>
|
178
|
-
|
190
|
+
<%= form.buttons do %>
|
179
191
|
<%= form.commit_button %>
|
180
192
|
<% end %>
|
181
193
|
<% end %>
|
@@ -184,19 +196,19 @@ You probably want control over the input type Formtastic uses for each field, yo
|
|
184
196
|
If you want to customize the label text, or render some hint text below the field, specify which fields are required/optional, or break the form into two fieldsets, the DSL is pretty comprehensive:
|
185
197
|
|
186
198
|
<pre>
|
187
|
-
|
188
|
-
|
199
|
+
<%= semantic_form_for @post do |form| %>
|
200
|
+
<%= form.inputs "Basic", :id => "basic" do %>
|
189
201
|
<%= form.input :title %>
|
190
202
|
<%= form.input :body %>
|
191
203
|
<% end %>
|
192
|
-
|
204
|
+
<%= form.inputs :name => "Advanced Options", :id => "advanced" do %>
|
193
205
|
<%= form.input :slug, :label => "URL Title", :hint => "Created automatically if left blank", :required => false %>
|
194
206
|
<%= form.input :section, :as => :radio %>
|
195
|
-
<%= form.input :user, :label => "Author", :
|
207
|
+
<%= form.input :user, :label => "Author", :member_label => :full_name %>
|
196
208
|
<%= form.input :categories, :required => false %>
|
197
209
|
<%= form.input :created_at, :as => :string, :label => "Publication Date", :required => false %>
|
198
210
|
<% end %>
|
199
|
-
|
211
|
+
<%= form.buttons do %>
|
200
212
|
<%= form.commit_button %>
|
201
213
|
<% end %>
|
202
214
|
<% end %>
|
@@ -205,15 +217,15 @@ If you want to customize the label text, or render some hint text below the fiel
|
|
205
217
|
You can create forms for nested resources:
|
206
218
|
|
207
219
|
<pre>
|
208
|
-
|
220
|
+
<%= semantic_form_for [@author, @post] do |form| %>
|
209
221
|
</pre>
|
210
222
|
|
211
223
|
Nested forms are also supported (don't forget your models need to be setup correctly with @accepts_nested_attributes_for@). You can do it in the Rails way:
|
212
224
|
|
213
225
|
<pre>
|
214
|
-
|
226
|
+
<%= semantic_form_for @post do |form| %>
|
215
227
|
<%= form.inputs :title, :body, :created_at %>
|
216
|
-
|
228
|
+
<%= form.semantic_fields_for :author do |author| %>
|
217
229
|
<%= author.inputs :first_name, :last_name, :name => "Author" %>
|
218
230
|
<% end %>
|
219
231
|
<%= form.buttons %>
|
@@ -223,7 +235,7 @@ Nested forms are also supported (don't forget your models need to be setup corre
|
|
223
235
|
Or the Formtastic way with the @:for@ option:
|
224
236
|
|
225
237
|
<pre>
|
226
|
-
|
238
|
+
<%= semantic_form_for @post do |form| %>
|
227
239
|
<%= form.inputs :title, :body, :created_at %>
|
228
240
|
<%= form.inputs :first_name, :last_name, :for => :author, :name => "Author" %>
|
229
241
|
<%= form.buttons %>
|
@@ -233,7 +245,7 @@ Or the Formtastic way with the @:for@ option:
|
|
233
245
|
When working in has many association, you can even supply @"%i"@ in your fieldset name that it will be properly interpolated with the child index. For example:
|
234
246
|
|
235
247
|
<pre>
|
236
|
-
|
248
|
+
<%= semantic_form_for @post do |form| %>
|
237
249
|
<%= form.inputs %>
|
238
250
|
<%= form.inputs :name => 'Category #%i', :for => :categories %>
|
239
251
|
<%= form.buttons %>
|
@@ -244,18 +256,18 @@ If you have more than one form on the same page, it may lead to HTML invalidatio
|
|
244
256
|
a namespace for your form to ensure uniqueness of id attributes on form elements. The namespace attribute will be prefixed with underscore on the generate html id. For example:
|
245
257
|
|
246
258
|
<pre>
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
259
|
+
<%= semantic_form_for(@post, :namespace => 'cat_form') do |form| %>
|
260
|
+
<%= form.input :title %> # id="cat_form_post_title"
|
261
|
+
<%= form.input :body %> # id="cat_form_post_body"
|
262
|
+
<%= form.input :created_at %> # id="cat_form_post_created_at"
|
263
|
+
<%= form.buttons %>
|
252
264
|
<% end %>
|
253
265
|
</pre>
|
254
266
|
|
255
267
|
Customize HTML attributes for any input using the @:input_html@ option. Typically this is used to disable the input, change the size of a text field, change the rows in a textarea, or even to add a special class to an input to attach special behavior like "autogrow":http://plugins.jquery.com/project/autogrow textareas:
|
256
268
|
|
257
269
|
<pre>
|
258
|
-
|
270
|
+
<%= semantic_form_for @post do |form| %>
|
259
271
|
<%= form.input :title, :input_html => { :cols => 10 } %>
|
260
272
|
<%= form.input :body, :input_html => { :class => 'autogrow', :rows => 10, :cols => 20, :maxlength => 10 } %>
|
261
273
|
<%= form.input :created_at, :input_html => { :disabled => true } %>
|
@@ -266,10 +278,10 @@ Customize HTML attributes for any input using the @:input_html@ option. Typicall
|
|
266
278
|
The same can be done for buttons with the @:button_html@ option:
|
267
279
|
|
268
280
|
<pre>
|
269
|
-
|
281
|
+
<%= semantic_form_for @post do |form| %>
|
270
282
|
...
|
271
|
-
|
272
|
-
<%= form.commit_button :button_html => { :class => "primary" } %>
|
283
|
+
<%= form.buttons do %>
|
284
|
+
<%= form.commit_button :button_html => { :class => "primary", :disable_with => 'Wait...' } %>
|
273
285
|
<% end %>
|
274
286
|
<% end %>
|
275
287
|
</pre>
|
@@ -277,7 +289,7 @@ The same can be done for buttons with the @:button_html@ option:
|
|
277
289
|
Customize the HTML attributes for the @<li>@ wrapper around every input with the @:wrapper_html@ option hash. There's one special key in the hash (@:class@), which will actually _append_ your string of classes to the existing classes provided by Formtastic (like @"required string error"@).
|
278
290
|
|
279
291
|
<pre>
|
280
|
-
|
292
|
+
<%= semantic_form_for @post do |form| %>
|
281
293
|
<%= form.input :title, :wrapper_html => { :class => "important" } %>
|
282
294
|
<%= form.input :body %>
|
283
295
|
<%= form.input :description, :wrapper_html => { :style => "display:none;" } %>
|
@@ -288,7 +300,7 @@ Customize the HTML attributes for the @<li>@ wrapper around every input with the
|
|
288
300
|
Customize the default class used for hints on each attribute or globally in the @config/formtastic.rb@ file. Similarly you can customize the error classes on an attribute level or globally.
|
289
301
|
|
290
302
|
<pre>
|
291
|
-
|
303
|
+
<%= semantic_form_for @post do |form| %>
|
292
304
|
<%= form.input :title, :hint_class => 'custom-html-class', :error_class => 'custom-error-class' %>
|
293
305
|
<% end %>
|
294
306
|
</pre>
|
@@ -326,7 +338,7 @@ The Formtastic input types:
|
|
326
338
|
* @:time@ - a time select. Default for column types: @:time@.
|
327
339
|
* @:boolean@ - a checkbox. Default for column types: @:boolean@.
|
328
340
|
* @:string@ - a text field. Default for column types: @:string@.
|
329
|
-
* @:
|
341
|
+
* @:number@ - a text field (just like string). Default for column types: @:integer@, @:float@, and @:decimal@.
|
330
342
|
* @:file@ - a file field. Default for file-attachment attributes matching: "paperclip":http://github.com/thoughtbot/paperclip or "attachment_fu":http://github.com/technoweenie/attachment_fu.
|
331
343
|
* @:country@ - a select menu of country names. Default for column types: :string with name @"country"@ - requires a *country_select* plugin to be installed.
|
332
344
|
* @:email@ - a text field (just like string). Default for columns with name matching @"email"@. New in HTML5. Works on some mobile browsers already.
|
@@ -334,6 +346,7 @@ The Formtastic input types:
|
|
334
346
|
* @:phone@ - a text field (just like string). Default for columns with name matching @"phone"@ or @"fax"@. New in HTML5.
|
335
347
|
* @:search@ - a text field (just like string). Default for columns with name matching @"search"@. New in HTML5. Works on Safari.
|
336
348
|
* @:hidden@ - a hidden field. Creates a hidden field (added for compatibility).
|
349
|
+
* @:range@ - a slider field.
|
337
350
|
|
338
351
|
The comments in the code are pretty good for each of these (what it does, what the output is, what the options are, etc.) so go check it out.
|
339
352
|
|
@@ -358,7 +371,7 @@ Formtastic got some neat I18n-features. ActiveRecord object names and attributes
|
|
358
371
|
Basic localization (labels only, with ActiveRecord):
|
359
372
|
|
360
373
|
<pre>
|
361
|
-
|
374
|
+
<%= semantic_form_for @post do |form| %>
|
362
375
|
<%= form.input :title %> # => :label => I18n.t('activerecord.attributes.user.title') or 'Title'
|
363
376
|
<%= form.input :body %> # => :label => I18n.t('activerecord.attributes.user.body') or 'Body'
|
364
377
|
<%= form.input :section %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
|
@@ -374,7 +387,7 @@ Formtastic supports localized *labels*, *hints*, *legends*, *actions* using the
|
|
374
387
|
*1. Enable I18n lookups by default (@config/initializers/formtastic.rb@):*
|
375
388
|
|
376
389
|
<pre>
|
377
|
-
Formtastic::
|
390
|
+
Formtastic::FormBuilder.i18n_lookups_by_default = true
|
378
391
|
</pre>
|
379
392
|
|
380
393
|
*2. Add some cool label-translations/variants (@config/locale/en.yml@):*
|
@@ -386,7 +399,7 @@ Formtastic supports localized *labels*, *hints*, *legends*, *actions* using the
|
|
386
399
|
post_details: "Post details"
|
387
400
|
labels:
|
388
401
|
post:
|
389
|
-
title: "
|
402
|
+
title: "Your Title"
|
390
403
|
body: "Write something..."
|
391
404
|
edit:
|
392
405
|
title: "Edit title"
|
@@ -394,6 +407,12 @@ Formtastic supports localized *labels*, *hints*, *legends*, *actions* using the
|
|
394
407
|
post:
|
395
408
|
title: "Choose a good title for you post."
|
396
409
|
body: "Write something inspiring here."
|
410
|
+
placeholders:
|
411
|
+
post:
|
412
|
+
title: "Title your post"
|
413
|
+
slug: "Leave blank for an automatically generated slug"
|
414
|
+
user:
|
415
|
+
email: "you@yours.com"
|
397
416
|
actions:
|
398
417
|
create: "Create my %{model}"
|
399
418
|
update: "Save changes"
|
@@ -405,13 +424,13 @@ Formtastic supports localized *labels*, *hints*, *legends*, *actions* using the
|
|
405
424
|
*3. ...and now you'll get:*
|
406
425
|
|
407
426
|
<pre>
|
408
|
-
|
409
|
-
|
427
|
+
<%= semantic_form_for Post.new do |form| %>
|
428
|
+
<%= form.inputs do %>
|
410
429
|
<%= form.input :title %> # => :label => "Choose a title...", :hint => "Choose a good title for you post."
|
411
430
|
<%= form.input :body %> # => :label => "Write something...", :hint => "Write something inspiring here."
|
412
431
|
<%= form.input :section %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
|
413
432
|
<% end %>
|
414
|
-
|
433
|
+
<%= form.buttons do %>
|
415
434
|
<%= form.commit_button %> # => "Create my %{model}"
|
416
435
|
<% end %>
|
417
436
|
<% end %>
|
@@ -422,8 +441,8 @@ Formtastic supports localized *labels*, *hints*, *legends*, *actions* using the
|
|
422
441
|
_Note: Slightly different because Formtastic can't guess how you group fields in a form. Legend text can be set with first (as in the sample below) specified value, or :name/:title options - depending on what flavor is preferred._
|
423
442
|
|
424
443
|
<pre>
|
425
|
-
|
426
|
-
|
444
|
+
<%= semantic_form_for @post do |form| %>
|
445
|
+
<%= form.inputs :post_details do %> # => :title => "Post details"
|
427
446
|
# ...
|
428
447
|
<% end %>
|
429
448
|
# ...
|
@@ -433,13 +452,13 @@ _Note: Slightly different because Formtastic can't guess how you group fields in
|
|
433
452
|
*5. Override I18n settings:*
|
434
453
|
|
435
454
|
<pre>
|
436
|
-
|
437
|
-
|
455
|
+
<%= semantic_form_for @post do |form| %>
|
456
|
+
<%= form.inputs do %>
|
438
457
|
<%= form.input :title %> # => :label => "Choose a title...", :hint => "Choose a good title for you post."
|
439
458
|
<%= form.input :body, :hint => false %> # => :label => "Write something..."
|
440
459
|
<%= form.input :section, :label => 'Some section' %> # => :label => 'Some section'
|
441
460
|
<% end %>
|
442
|
-
|
461
|
+
<%= form.buttons do %>
|
443
462
|
<%= form.commit_button :dummie %> # => "Launch!"
|
444
463
|
<% end %>
|
445
464
|
<% end %>
|
@@ -448,19 +467,19 @@ _Note: Slightly different because Formtastic can't guess how you group fields in
|
|
448
467
|
If I18n-lookups is disabled, i.e.:
|
449
468
|
|
450
469
|
<pre>
|
451
|
-
Formtastic::
|
470
|
+
Formtastic::FormBuilder.i18n_lookups_by_default = false
|
452
471
|
</pre>
|
453
472
|
|
454
473
|
...then you can enable I18n within the forms instead:
|
455
474
|
|
456
475
|
<pre>
|
457
|
-
|
458
|
-
|
476
|
+
<%= semantic_form_for @post do |form| %>
|
477
|
+
<%= form.inputs do %>
|
459
478
|
<%= form.input :title, :label => true %> # => :label => "Choose a title..."
|
460
479
|
<%= form.input :body, :label => true %> # => :label => "Write something..."
|
461
480
|
<%= form.input :section, :label => true %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
|
462
481
|
<% end %>
|
463
|
-
|
482
|
+
<%= form.buttons do %>
|
464
483
|
<%= form.commit_button true %> # => "Update %{model}" (if we are in edit that is...)
|
465
484
|
<% end %>
|
466
485
|
<% end %>
|
@@ -506,116 +525,107 @@ h2. Semantic errors
|
|
506
525
|
You can show errors on base (by default) and any other attribute just passing it name to semantic_errors method:
|
507
526
|
|
508
527
|
<pre>
|
509
|
-
|
528
|
+
<%= semantic_form_for @post do |form| %>
|
510
529
|
<%= form.semantic_errors :state %>
|
511
530
|
<% end %>
|
512
531
|
</pre>
|
513
532
|
|
514
533
|
|
515
|
-
h2. ValidationReflection plugin
|
516
|
-
|
517
|
-
If you have the "ValidationReflection":http://github.com/redinger/validation_reflection plugin installed, you won't have to specify the @:required@ option (it checks the validations on the model instead).
|
518
|
-
|
519
|
-
|
520
534
|
h2. Configuration
|
521
535
|
|
522
|
-
Run @rails generate formtastic:install@
|
536
|
+
Run @rails generate formtastic:install@ to copy a commented out config file into @config/initializers/formtastic.rb@. You can "view the configuration file on GitHub":http://github.com/justinfrench/formtastic/blob/master/lib/generators/templates/formtastic.rb
|
523
537
|
|
524
538
|
|
525
539
|
h2. Form Generator
|
526
540
|
|
527
|
-
There's a Formtastic form code generator to make your transition to Formtastic easier. All you have to do is to *specify an existing model name*, and optionally specify view template framework (ERB/HAML), and you are good to go. *Note:* This won't overwrite any of your
|
541
|
+
There's a Formtastic form code generator to make your transition to Formtastic easier. All you have to do is to *specify an existing model name*, and optionally specify view template framework (ERB/HAML), and you are good to go. *Note:* This won't overwrite any of your exsting files without confirmation.
|
528
542
|
|
529
543
|
h3. Basic usage
|
530
544
|
|
531
|
-
Rails 3:
|
532
|
-
|
533
545
|
<pre>
|
534
546
|
$ rails generate formtastic:form ModelName
|
547
|
+
exists app/views/posts
|
548
|
+
create app/views/posts/_form.html.erb
|
535
549
|
</pre>
|
536
550
|
|
537
|
-
|
551
|
+
The ERB code is saved to a partial file, but it will not overwrite existing files without a prompt.
|
552
|
+
|
553
|
+
h3. Copying the ERB code to the clipboard instead with @--copy@
|
538
554
|
|
539
555
|
<pre>
|
540
|
-
$
|
556
|
+
$ rails generate formtastic:form Post --copy
|
541
557
|
</pre>
|
542
558
|
|
543
|
-
|
559
|
+
h3. Specifying HAML instead of ERB with @--haml@
|
544
560
|
|
545
561
|
<pre>
|
546
|
-
$ rails generate formtastic:form Post
|
547
|
-
|
548
|
-
|
549
|
-
|
562
|
+
$ rails generate formtastic:form Post --haml
|
563
|
+
exists app/views/posts
|
564
|
+
create app/views/posts/_form.html.haml
|
565
|
+
</pre>
|
550
566
|
|
551
|
-
|
552
|
-
<%= f.input :title, :label => 'Title' %>
|
553
|
-
<%= f.input :body, :label => 'Body' %>
|
554
|
-
<%= f.input :published, :label => 'Published' %>
|
555
|
-
<% end %>
|
567
|
+
h3. Specifying controller namespace with @--controller@
|
556
568
|
|
557
|
-
|
558
|
-
|
569
|
+
<pre>
|
570
|
+
$ rails generate formtastic:form Post --controller admin/posts
|
571
|
+
exists app/views/admin/posts
|
572
|
+
create app/views/admin/posts/_form.html.erb
|
559
573
|
</pre>
|
560
574
|
|
561
|
-
h3.
|
562
|
-
|
563
|
-
You can also ask Formtastic to *generate a partial* with the @--partial@ option, placing it in the correct location inside your @app/views@ directory:
|
575
|
+
h3. Specifying which attributes need an input
|
564
576
|
|
565
577
|
<pre>
|
566
|
-
$ rails generate formtastic:form Post
|
578
|
+
$ rails generate formtastic:form Post title:string body:text publication_state:select
|
567
579
|
exists app/views/posts
|
568
580
|
create app/views/posts/_form.html.erb
|
569
581
|
</pre>
|
570
582
|
|
571
|
-
h3. Specifying HAML instead of ERB with @--haml@
|
572
583
|
|
573
|
-
<pre>
|
574
|
-
$ rails generate formtastic:form Post --haml
|
575
|
-
exists app/views/admin/posts
|
576
|
-
create app/views/admin/posts/_form.html.haml
|
577
|
-
</pre>
|
578
584
|
|
579
|
-
|
585
|
+
h2. Modified & Custom Inputs
|
586
|
+
|
587
|
+
If you want to change the behaviour of an input, you can subclass it in your app. For example, to tweak @StringInput@, create a new file @app/inputs/string_input.rb@:
|
580
588
|
|
581
589
|
<pre>
|
582
|
-
|
583
|
-
|
584
|
-
|
590
|
+
class StringInput < Formtastic::Inputs::StringInput
|
591
|
+
def to_html
|
592
|
+
puts "this is my modified version of StringInput"
|
593
|
+
super
|
594
|
+
end
|
595
|
+
end
|
585
596
|
</pre>
|
586
597
|
|
598
|
+
To create your own new types of inputs based on existing inputs, the process is similar:
|
587
599
|
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
600
|
+
<pre>
|
601
|
+
# f.input(:body, :as => :flexible_text)
|
602
|
+
class FlexibleTextInput < Formtastic::Inputs::StringInput
|
603
|
+
def input_html_options
|
604
|
+
super.merge(:class => "flexible-text-area")
|
605
|
+
end
|
606
|
+
end
|
607
|
+
</pre>
|
593
608
|
|
594
|
-
|
609
|
+
To create your own new types of inputs from scratch:
|
595
610
|
|
596
611
|
<pre>
|
597
|
-
#
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
Formtastic::SemanticFormHelper.builder = Formtastic::MyCustomBuilder
|
605
|
-
Formtastic::MyCustomBuilder.i18n_lookups_by_default = true
|
606
|
-
|
607
|
-
# WRONG!
|
608
|
-
require 'formtastic/my_custom_builder'
|
609
|
-
Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
|
610
|
-
Formtastic::SemanticFormHelper.builder = Formtastic::MyCustomBuilder
|
612
|
+
# f.input(:created_at, :as => :date_picker)
|
613
|
+
class DatePickerInput
|
614
|
+
include Formtastic::Inputs::Base
|
615
|
+
def to_html
|
616
|
+
# ...
|
617
|
+
end
|
618
|
+
end
|
611
619
|
</pre>
|
612
620
|
|
621
|
+
It was previously advised to subclass Formtastic::FormBuilder to add your own inputs. This is no longer advised, and may not work as expected.
|
622
|
+
|
613
623
|
|
614
624
|
h2. Security
|
615
625
|
|
616
626
|
By default formtastic escapes html entities in both labels and hints unless a string is marked as html_safe. If you are using an older rails version which doesn't know html_safe, or you want to globally turn this feature off, you can set the following in your initializer:
|
617
627
|
|
618
|
-
Formtastic::
|
628
|
+
Formtastic::FormBuilder.escape_html_entities_in_hints_and_labels = false
|
619
629
|
|
620
630
|
|
621
631
|
h2. Dependencies
|
@@ -623,16 +633,10 @@ h2. Dependencies
|
|
623
633
|
There are none, but...
|
624
634
|
|
625
635
|
* if you have the "ValidationReflection":http://github.com/redinger/validation_reflection plugin is installed, you won't have to specify the @:required@ option (it checks the validations on the model instead).
|
626
|
-
* if you want to use the @:country@ input, you'll need to install the "
|
636
|
+
* if you want to use the @:country@ input, you'll need to install the "country-select plugin":https://github.com/chrislerum/country_select (or any other country_select plugin with the same API).
|
627
637
|
* "rspec":http://github.com/dchelimsky/rspec/, "rspec_hpricot_matchers":http://rubyforge.org/projects/rspec-hpricot/ and "rcov":http://github.com/relevance/rcov gems (plus any of their own dependencies) are required for the test suite.
|
628
638
|
|
629
639
|
|
630
|
-
h2. Compatibility
|
631
|
-
|
632
|
-
* We're only testing Formtastic with the latest Rails 2.x and 3.x stable releases. Patches are welcome to allow backwards compatibility with older versions of Rails, of course.
|
633
|
-
* Formtastic, much like Rails 2, is very ActiveRecord-centric. Many people are using Formtastic (especially the rails3 branch) successfully with other ActiveModel-like ORMs and classes (DataMapper, MongoMapper, Mongoid, Authlogic, Devise...) but we're not guaranteeing anything at this stage. Patches are welcome, but it's not our core focus right now.
|
634
|
-
|
635
|
-
|
636
640
|
h2. How to contribute
|
637
641
|
|
638
642
|
Please ensure that you provide appropriate spec/test coverage and ensure the documentation is up-to-date. Bonus points if you perform your changes in a clean topic branch rather than master, and if you create a pull request for your changes to be discussed and reviewed.
|
@@ -644,39 +648,18 @@ For significant changes, you may wish to discuss your idea on the Formtastic Goo
|
|
644
648
|
See below for installation of a development environment.
|
645
649
|
|
646
650
|
|
647
|
-
h2. Development Environment
|
648
|
-
|
649
|
-
We currently support both Rails 2 and Rails 3, under Ruby 1.8.7-ish (and 1.9.2-ish). That means, at a bare minimum, you'll want to set-up two rvm gemsets to run your specs against. So, fork the project on Github, clone it, make some gemsets, run bundler, run your specs and then finally set-up an .rvmrc file that specifies Rails 3 as your default gemset and cd back into that directory to load in the .rvmrc file. Something like this:
|
650
|
-
|
651
|
-
<pre>
|
652
|
-
$ cd ~/code/formtastic
|
653
|
-
$ rvm gemset create formtastic # If that's your thing
|
654
|
-
$ rvm gemset use formtastic # Add that to your .rvmrc too
|
655
|
-
$ bundle install # Initial bundle command to build Gemfile.lock
|
656
|
-
$ RAILS_2=true bundle update rails # Updates gemfile to run agains rails 2
|
657
|
-
$ RAILS_2=true rake # Run tests against rails 2
|
658
|
-
$ bundle update rails # Updates gemfile to run agains rails 3
|
659
|
-
$ rake # Run tests against rails 3
|
660
|
-
</pre>
|
661
|
-
|
662
|
-
|
663
|
-
h2. Maintainers & Contributors
|
664
|
-
|
665
|
-
Formtastic is maintained by "Justin French":http://github.com/justinfrench, "Morton Jonuschat":http://github.com/yabawock and "Gabriel Sobrinho":http://github.com/sobrinho. "Denis Major":http://github.com/denismajor1 is doing some amazing documentation work in the wiki, and we very much appreciate the past efforts of "José Valim":http://github.com/josevalim and "Jonas Grimfelt":http://github.com/grimen and over 40 other contributors.
|
666
|
-
|
667
|
-
@git shortlog -n -s --no-merges@
|
668
|
-
|
669
|
-
|
670
651
|
h2. Google Group, Twitter, etc
|
671
652
|
|
672
653
|
Please join the "Formtastic Google Group":http://groups.google.com.au/group/formtastic, especially if you'd like to talk about a new feature, or report a bug.
|
673
654
|
|
674
655
|
You can also "follow @formtastic on Twitter":http://twitter.com/formtastic for announcements, tutorials and awesome Formtastic links.
|
675
656
|
|
676
|
-
|
677
657
|
h2. Project Info
|
678
658
|
|
679
|
-
Formtastic
|
659
|
+
Formtastic was created by "Justin French":http://www.justinfrench.com with contributions from over 100 awesome developers.
|
660
|
+
|
661
|
+
Run @git shortlog -n -s@ to see the awesome.
|
680
662
|
|
663
|
+
The project is hosted on Github: "http://github.com/justinfrench/formtastic":http://github.com/justinfrench/formtastic, where your contributions, forkings, comments, issues and feedback are greatly welcomed.
|
681
664
|
|
682
665
|
Copyright (c) 2007-2010 Justin French, released under the MIT license.
|