Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 628 lines (456 sloc) 27.946 kb
420b4ce @justinfrench sick of updating the README with every version bump :)
authored
1 h1. Formtastic
dcf8beb Initial Commit
Justin French authored
2
3 Formtastic is a Rails FormBuilder DSL (with some other goodies) to make it far easier to create beautiful, semantically rich, syntactically awesome, readily stylable and wonderfully accessible HTML forms in your Rails applications.
4
cd0a1ba @justinfrench pledgie image URL is a redirect, so here's the real URL
authored
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>
1bbe8ea @justinfrench add the pledgie badge back in, GH don't show them any more?
authored
6
09d957d textilized the README so that it looks pretty pretty on GitHub
Justin French authored
7 h2. The Story
dcf8beb Initial Commit
Justin French authored
8
2d4a72b @justinfrench big update to the README
authored
9 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:
dcf8beb Initial Commit
Justin French authored
10
09d957d textilized the README so that it looks pretty pretty on GitHub
Justin French authored
11 <pre>
7e3874a @justinfrench trying to fix README formatting of <'s at the start of lines
authored
12 <% semantic_form_for @article do |form| %>
353618e @markmansour Extending Formtastic can be done by overriding the semantic_form_buil…
markmansour authored
13
0b370ba @justinfrench Renamed input_field_set() to just inputs() and added a shorthand vers…
authored
14 <% form.inputs :name => "Basic" do %>
353618e @markmansour Extending Formtastic can be done by overriding the semantic_form_buil…
markmansour authored
15 <%= form.input :title %>
16 <%= form.input :body %>
1db292f @sprsquish update README to reflect association attribute changes
sprsquish authored
17 <%= form.input :section %>
18 <%= form.input :publication_state, :as => :radio %>
9997ce6 @josevalim Added more information about inputs :for in README.
josevalim authored
19 <%= form.input :category %>
353618e @markmansour Extending Formtastic can be done by overriding the semantic_form_buil…
markmansour authored
20 <%= form.input :allow_comments, :label => "Allow commenting on this article" %>
21 <% end %>
22
0b370ba @justinfrench Renamed input_field_set() to just inputs() and added a shorthand vers…
authored
23 <% form.inputs :name => "Advanced" do %>
353618e @markmansour Extending Formtastic can be done by overriding the semantic_form_buil…
markmansour authored
24 <%= form.input :keywords, :required => false, :hint => "Example: ruby, rails, forms" %>
7e3874a @justinfrench trying to fix README formatting of <'s at the start of lines
authored
25 <%= form.input :extract, :required => false %>
26 <%= form.input :description, :required => false %>
353618e @markmansour Extending Formtastic can be done by overriding the semantic_form_buil…
markmansour authored
27 <%= form.input :url_title, :required => false %>
7e3874a @justinfrench trying to fix README formatting of <'s at the start of lines
authored
28 <% end %>
29
05ae54d @josevalim Fixed nested attributes example in README
josevalim authored
30 <% form.inputs :name => "Author", :for => :author do |author_form| %>
31 <%= author_form.input :first_name %>
32 <%= author_form.input :last_name %>
9997ce6 @josevalim Added more information about inputs :for in README.
josevalim authored
33 <% end %>
34
353618e @markmansour Extending Formtastic can be done by overriding the semantic_form_buil…
markmansour authored
35 <% form.buttons do %>
36 <%= form.commit_button %>
7e3874a @justinfrench trying to fix README formatting of <'s at the start of lines
authored
37 <% end %>
09d957d textilized the README so that it looks pretty pretty on GitHub
Justin French authored
38
dcf8beb Initial Commit
Justin French authored
39 <% end %>
09d957d textilized the README so that it looks pretty pretty on GitHub
Justin French authored
40 </pre>
41
6734cfd @justinfrench sme typos and cleanups in the readme
authored
42 I also wrote the accompanying HTML output I expected, favoring something very similar to the fieldsets, lists and other semantic elements Aaron Gustafson presented in "Learning to Love Forms":http://www.slideshare.net/AaronGustafson/learning-to-love-forms-web-directions-south-07, hacking together enough Ruby to prove it could be done.
dcf8beb Initial Commit
Justin French authored
43
44
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
45 h2. It's better than _SomeOtherFormBuilder_ because...
46
6688887 @grimen More README-polishing.
grimen authored
47 * 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 * 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.
3340c53 @justinfrench Remove Rails 2 stuff from README
authored
49 * it's Rails 3 compatible (including nested forms).
f02b136 @justinfrench rearranged and beefed up the 'it's better than...' README section
authored
50 * it has internationalization (I18n)!
6688887 @grimen More README-polishing.
grimen authored
51 * 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 * there's heaps of elements, id and class attributes for you to hook in your CSS and JS.
53 * it handles real world stuff like inline hints, inline error messages & help text.
54 * 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 * it's got absolutely awesome spec coverage.
56 * there's a bunch of people using and working on it (it's not just one developer building half a solution).
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
57
58
15e0bd9 updated the README a little to match last night's slides
Justin French authored
59 h2. Why?
60
6688887 @grimen More README-polishing.
grimen authored
61 * web apps = lots of forms.
62 * forms are so friggin' boring to code.
63 * semantically rich & accessible forms really are possible.
64 * the "V" is way behind the "M" and "C" in Rails' MVC – it's the ugly sibling.
65 * best practices and common patterns have to start somewhere.
66 * i need a challenge.
dcf8beb Initial Commit
Justin French authored
67
68
15e0bd9 updated the README a little to match last night's slides
Justin French authored
69 h2. Opinions
70
6688887 @grimen More README-polishing.
grimen authored
71 * it should be easier to do things the right way than the wrong way.
72 * sometimes _more mark-up_ is better.
73 * elements and attribute hooks are _gold_ for stylesheet authors.
74 * make the common things we do easy, yet still ensure uncommon things are still possible.
15e0bd9 updated the README a little to match last night's slides
Justin French authored
75
dcf8beb Initial Commit
Justin French authored
76
3dd6455 @justinfrench Link to RDoc URL in README
authored
77 h2. Documentation
78
79 RDoc documentation _should_ be automatically generated after each commit and made available on the "rdoc.info website":http://rdoc.info/projects/justinfrench/formtastic.
80
81
e3f04f6 @justinfrench README installation instructions simlified and clarified to specific …
authored
82 h2. Installation
c89e985 @justinfrench updating README with gem/plugin installation instructions
authored
83
3340c53 @justinfrench Remove Rails 2 stuff from README
authored
84 Formtastic 2 compatible with Rails 3 only, and the gem is "hosted":http://rubygems.org/gems/formtastic on RubyGems.org.
557f929 @justinfrench updated README to reflect new 1.1.0.beta gem, etc
authored
85
ebe4e51 @justinfrench updated the README to reflect the new gem versions and other compatib…
authored
86 Simply add Formtastic to your Gemfile and bundle it up:
557f929 @justinfrench updated README to reflect new 1.1.0.beta gem, etc
authored
87
88 <pre>
3340c53 @justinfrench Remove Rails 2 stuff from README
authored
89 gem 'formtastic', '~> 2.0.0'
557f929 @justinfrench updated README to reflect new 1.1.0.beta gem, etc
authored
90 </pre>
91
e3f04f6 @justinfrench README installation instructions simlified and clarified to specific …
authored
92 Optionally, run the generator to copy some stylesheets and a configuration initializer into your application:
c89e985 @justinfrench updating README with gem/plugin installation instructions
authored
93
94 <pre>
e3f04f6 @justinfrench README installation instructions simlified and clarified to specific …
authored
95 $ rails generate formtastic:install
c89e985 @justinfrench updating README with gem/plugin installation instructions
authored
96 </pre>
97
ebe4e51 @justinfrench updated the README to reflect the new gem versions and other compatib…
authored
98
99 h2. Stylesheets
c89e985 @justinfrench updating README with gem/plugin installation instructions
authored
100
127a6b9 @justinfrench Added a Formtastic::LayoutHelper with formtastic_stylesheets so that …
authored
101 A proof-of-concept stylesheet is provided which you can include in your layout. Customization is best achieved by overriding these styles in an additional stylesheet so that the Formtastic styles can be updated without clobbering your changes. If you want to use these stylesheets, add both to your layout with this helper:
c89e985 @justinfrench updating README with gem/plugin installation instructions
authored
102
5c1ce48 @justinfrench moved the stylesheets stuff up with installation
authored
103 <pre>
127a6b9 @justinfrench Added a Formtastic::LayoutHelper with formtastic_stylesheets so that …
authored
104 <head>
105 ...
106 <%= formtastic_stylesheet_link_tag %>
107 ...
108 </head>
5c1ce48 @justinfrench moved the stylesheets stuff up with installation
authored
109 </pre>
2526d2c @justinfrench Going back to generators instead of Rake tasks for copying stylesheet…
authored
110
4036e74 @justinfrench pruning and cleaning up the README, it's been a while
authored
111
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
112 h2. Usage
113
114 Forms are really boring to code... you want to get onto the good stuff as fast as possible.
115
6688887 @grimen More README-polishing.
grimen authored
116 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:
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
117
118 <pre>
119 <% semantic_form_for @user do |form| %>
120 <%= form.inputs %>
121 <%= form.buttons %>
122 <% end %>
123 </pre>
124
5018ed0 @justinfrench clarified the differences in Rails 2 and 3 ERB blocks, and some other…
authored
125 This is a great way to get something up fast, but like scaffolding, it's not recommended for production.
126
127 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@:
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
128
129 <pre>
130 <% semantic_form_for @user do |form| %>
131 <%= form.inputs :title, :body, :section, :categories, :created_at %>
132 <%= form.buttons :commit %>
133 <% end %>
134 </pre>
135
5018ed0 @justinfrench clarified the differences in Rails 2 and 3 ERB blocks, and some other…
authored
136 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):
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
137
138 <pre>
139 <% semantic_form_for @post do |form| %>
140 <% form.inputs do %>
141 <%= form.input :title %>
142 <%= form.input :body %>
143 <%= form.input :section, :as => :radio %>
144 <%= form.input :categories %>
145 <%= form.input :created_at, :as => :string %>
146 <% end %>
147 <% form.buttons do %>
148 <%= form.commit_button %>
149 <% end %>
150 <% end %>
151 </pre>
152
a45853c @justinfrench small README typo
authored
153 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:
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
154
155 <pre>
156 <% semantic_form_for @post do |form| %>
17f6668 @justinfrench Revert "This reverts commit 440bd2d8da117acdbca57fa199c115caefcd87c0."
authored
157 <% form.inputs "Basic", :id => "basic" do %>
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
158 <%= form.input :title %>
159 <%= form.input :body %>
160 <% end %>
161 <% form.inputs :name => "Advanced Options", :id => "advanced" do %>
162 <%= form.input :slug, :label => "URL Title", :hint => "Created automatically if left blank", :required => false %>
163 <%= form.input :section, :as => :radio %>
d174db0 @asanghi change id_prefix to namespace; added documentation in README
asanghi authored
164 <%= form.input :user, :label => "Author", :label_method => :full_name %>
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
165 <%= form.input :categories, :required => false %>
166 <%= form.input :created_at, :as => :string, :label => "Publication Date", :required => false %>
167 <% end %>
168 <% form.buttons do %>
169 <%= form.commit_button %>
170 <% end %>
171 <% end %>
172 </pre>
173
4033f27 @nathanl Small addition to documentation
nathanl authored
174 You can create forms for nested resources:
175
176 <pre>
177 <% semantic_form_for [@author, @post] do |form| %>
178 </pre>
179
bcd3ba9 @justinfrench some README updates
authored
180 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:
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
181
182 <pre>
05ae54d @josevalim Fixed nested attributes example in README
josevalim authored
183 <% semantic_form_for @post do |form| %>
184 <%= form.inputs :title, :body, :created_at %>
41a6754 @josevalim Another README fix.
josevalim authored
185 <% form.semantic_fields_for :author do |author| %>
1fcc068 @grimen An effort to make the README somewhat more readable.
grimen authored
186 <%= author.inputs :first_name, :last_name, :name => "Author" %>
41a6754 @josevalim Another README fix.
josevalim authored
187 <% end %>
05ae54d @josevalim Fixed nested attributes example in README
josevalim authored
188 <%= form.buttons %>
9997ce6 @josevalim Added more information about inputs :for in README.
josevalim authored
189 <% end %>
190 </pre>
191
6fd1bd2 @justinfrench improving the documentation in README
authored
192 Or the Formtastic way with the @:for@ option:
9997ce6 @josevalim Added more information about inputs :for in README.
josevalim authored
193
194 <pre>
05ae54d @josevalim Fixed nested attributes example in README
josevalim authored
195 <% semantic_form_for @post do |form| %>
196 <%= form.inputs :title, :body, :created_at %>
197 <%= form.inputs :first_name, :last_name, :for => :author, :name => "Author" %>
198 <%= form.buttons %>
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
199 <% end %>
200 </pre>
201
1fcc068 @grimen An effort to make the README somewhat more readable.
grimen authored
202 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:
d5e3b0a @josevalim Added nested child nindex support.
josevalim authored
203
204 <pre>
205 <% semantic_form_for @post do |form| %>
206 <%= form.inputs %>
207 <%= form.inputs :name => 'Category #%i', :for => :categories %>
208 <%= form.buttons %>
209 <% end %>
210 </pre>
211
d174db0 @asanghi change id_prefix to namespace; added documentation in README
asanghi authored
212 If you have more than one form on the same page, it may lead to HTML invalidation because of the way HTML element id attributes are assigned. You can provide
213 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:
214
215 <pre>
216 <% semantic_form_for(@post, :namespace => 'cat_form') do |form| %>
217 <%= form.input :title %> # id="cat_form_post_title"
218 <%= form.input :body %> # id="cat_form_post_body"
219 <%= form.input :created_at %> # id="cat_form_post_created_at"
220 <%= form.buttons %>
221 <% end %>
222 </pre>
6fd1bd2 @justinfrench improving the documentation in README
authored
223
29133e1 @dougireton Fixed minor typo in README Usage section.
dougireton authored
224 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:
6fd1bd2 @justinfrench improving the documentation in README
authored
225
226 <pre>
227 <% semantic_form_for @post do |form| %>
228 <%= form.input :title, :input_html => { :size => 60 } %>
229 <%= form.input :body, :input_html => { :class => 'autogrow' } %>
230 <%= form.input :created_at, :input_html => { :disabled => true } %>
231 <%= form.buttons %>
232 <% end %>
233 </pre>
234
235 The same can be done for buttons with the @:button_html@ option:
236
237 <pre>
238 <% semantic_form_for @post do |form| %>
239 ...
240 <% form.buttons do %>
241 <%= form.commit_button :button_html => { :class => "primary" } %>
242 <% end %>
243 <% end %>
244 </pre>
245
d174db0 @asanghi change id_prefix to namespace; added documentation in README
asanghi authored
246 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"@).
1fcc068 @grimen An effort to make the README somewhat more readable.
grimen authored
247
6fd1bd2 @justinfrench improving the documentation in README
authored
248 <pre>
249 <% semantic_form_for @post do |form| %>
250 <%= form.input :title, :wrapper_html => { :class => "important" } %>
251 <%= form.input :body %>
252 <%= form.input :description, :wrapper_html => { :style => "display:none;" } %>
253 ...
254 <% end %>
255 </pre>
256
d174db0 @asanghi change id_prefix to namespace; added documentation in README
asanghi authored
257 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.
258
259 <pre>
260 <% semantic_form_for @post do |form| %>
261 <%= form.input :title, :hint_class => 'custom-html-class', :error_class => 'custom-error-class' %>
262 <% end %>
263 </pre>
264
a92cf7c @justinfrench added documentation for :collection option, resolves #181
authored
265 Many inputs provide a collection of options to choose from (like @:select@, @:radio@, @:check_boxes@, @:boolean@). In many cases, Formtastic can find choices through the model associations, but if you want to use your own set of choices, the @:collection@ option is what you want. You can pass in an Array of objects, an array of Strings, a Hash... Throw almost anything at it! Examples:
266
267 <pre>
268 f.input :authors, :as => :check_boxes, :collection => User.find(:all, :order => "last_name ASC")
269 f.input :authors, :as => :check_boxes, :collection => current_user.company.users.active
270 f.input :authors, :as => :check_boxes, :collection => [@justin, @kate]
271 f.input :authors, :as => :check_boxes, :collection => ["Justin", "Kate", "Amelia", "Gus", "Meg"]
272 f.input :author, :as => :select, :collection => Author.find(:all)
273 f.input :author, :as => :select, :collection => { @justin.name => @justin.id, @kate.name => @kate.id }
274 f.input :author, :as => :select, :collection => ["Justin", "Kate", "Amelia", "Gus", "Meg"]
275 f.input :author, :as => :radio, :collection => User.find(:all)
276 f.input :author, :as => :radio, :collection => [@justin, @kate]
277 f.input :author, :as => :radio, :collection => { @justin.name => @justin.id, @kate.name => @kate.id }
278 f.input :author, :as => :radio, :collection => ["Justin", "Kate", "Amelia", "Gus", "Meg"]
279 f.input :admin, :as => :radio, :collection => ["Yes!", "No"]
280 </pre>
281
6fd1bd2 @justinfrench improving the documentation in README
authored
282
5a39443 @justinfrench bulking up the documentation and readme with the different inputs ava…
authored
283 h2. The Available Inputs
284
d9a06fe @grimen README: Last set of polishing moves for now.
grimen authored
285 The Formtastic input types:
286
8577c18 @grimen More README-readability polishing.
grimen authored
287 * @:select@ - a select menu. Default for ActiveRecord associations: @belongs_to@, @has_many@, and @has_and_belongs_to_many@.
288 * @:check_boxes@ - a set of check_box inputs. Alternative to @:select@ for ActiveRecord-associations: @has_many@, and @has_and_belongs_to_many@.
289 * @:radio@ - a set of radio inputs. Alternative to @:select@ for ActiveRecord-associations: @belongs_to@.
290 * @:time_zone@ - a select input. Default for column types: @:string@ with name matching @"time_zone"@.
291 * @:password@ - a password input. Default for column types: @:string@ with name matching @"password"@.
292 * @:text@ - a textarea. Default for column types: @:text@.
293 * @:date@ - a date select. Default for column types: @:date@.
294 * @:datetime@ - a date and time select. Default for column types: @:datetime@ and @:timestamp@.
295 * @:time@ - a time select. Default for column types: @:time@.
296 * @:boolean@ - a checkbox. Default for column types: @:boolean@.
297 * @:string@ - a text field. Default for column types: @:string@.
298 * @:numeric@ - a text field (just like string). Default for column types: @:integer@, @:float@, and @:decimal@.
299 * @: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.
300 * @:country@ - a select menu of country names. Default for column types: :string with name @"country"@ - requires a *country_select* plugin to be installed.
e0a7874 @asanghi Added auto-guessing and updated some docs
asanghi authored
301 * @:email@ - a text field (just like string). Default for columns with name matching @"email"@. New in HTML5. Works on some mobile browsers already.
302 * @:url@ - a text field (just like string). Default for columns with name matching @"url"@. New in HTML5. Works on some mobile browsers already.
303 * @:phone@ - a text field (just like string). Default for columns with name matching @"phone"@ or @"fax"@. New in HTML5.
304 * @:search@ - a text field (just like string). Default for columns with name matching @"search"@. New in HTML5. Works on Safari.
6688887 @grimen More README-polishing.
grimen authored
305 * @:hidden@ - a hidden field. Creates a hidden field (added for compatibility).
306
fd23ef4 @justinfrench tiny README tweak
authored
307 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.
308
5a39443 @justinfrench bulking up the documentation and readme with the different inputs ava…
authored
309
06ff25d @lardawge Added section clarifying label lookup order.
lardawge authored
310 h2. Delegation for label lookups
311
312 Formtastic decides which label to use in the following order:
313
314 <pre>
315 1. :label # :label => "Choose Title"
316 2. Formtastic i18n # if either :label => true || i18n_lookups_by_default = true (see Internationalization)
317 3. Activerecord i18n # if localization file found for the given attribute
318 4. label_str_method # if nothing provided this defaults to :humanize but can be set to a custom method
319 </pre>
320
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
321 h2. Internationalization (I18n)
322
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to…
grimen authored
323 h3. Basic Localization
71ef99f @justinfrench nuked the configuration copy/paste from the README, linked to the gen…
authored
324
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to…
grimen authored
325 Formtastic got some neat I18n-features. ActiveRecord object names and attributes are, by default, taken from calling @@object.human_name@ and @@object.human_attribute_name(attr)@ respectively. There are a few words specific to Formtastic that can be translated. See @lib/locale/en.yml@ for more information.
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
326
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset…
grimen authored
327 Basic localization (labels only, with ActiveRecord):
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
328
329 <pre>
330 <% semantic_form_for @post do |form| %>
331 <%= form.input :title %> # => :label => I18n.t('activerecord.attributes.user.title') or 'Title'
332 <%= form.input :body %> # => :label => I18n.t('activerecord.attributes.user.body') or 'Body'
333 <%= form.input :section %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
334 <% end %>
335 </pre>
336
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to…
grimen authored
337 *Note:* This is perfectly fine if you just want your labels/attributes and/or models to be translated using *ActiveRecord I18n attribute translations*, and you don't use input hints and legends. But what if you do? And what if you don't want same labels in all forms?
338
339 h3. Enhanced Localization (Formtastic I18n API)
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
340
d9a06fe @grimen README: Last set of polishing moves for now.
grimen authored
341 Formtastic supports localized *labels*, *hints*, *legends*, *actions* using the I18n API for more advanced usage. Your forms can now be DRYer and more flexible than ever, and still fully localized. This is how:
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
342
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to…
grimen authored
343 *1. Enable I18n lookups by default (@config/initializers/formtastic.rb@):*
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
344
345 <pre>
346 Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
347 </pre>
348
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to…
grimen authored
349 *2. Add some cool label-translations/variants (@config/locale/en.yml@):*
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
350
351 <pre>
352 en:
353 formtastic:
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset…
grimen authored
354 titles:
355 post_details: "Post details"
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
356 labels:
357 post:
358 title: "Choose a title..."
359 body: "Write something..."
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset…
grimen authored
360 edit:
361 title: "Edit title"
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
362 hints:
363 post:
364 title: "Choose a good title for you post."
365 body: "Write something inspiring here."
4aca8cd @grimen New I18n-features:
grimen authored
366 actions:
743b26b @yabawock Revert "Reverting two i18n patches pulled in from the rails3 branch w…
yabawock authored
367 create: "Create my %{model}"
4aca8cd @grimen New I18n-features:
grimen authored
368 update: "Save changes"
369 dummie: "Launch!"
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
370 </pre>
371
372 *Note:* We are using English here still, but you get the point.
373
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to…
grimen authored
374 *3. ...and now you'll get:*
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
375
376 <pre>
4aca8cd @grimen New I18n-features:
grimen authored
377 <% semantic_form_for Post.new do |form| %>
a8e2f2e @justinfrench fix README examples missing form.x prefix for buttons and inputs
authored
378 <% form.inputs do %>
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset…
grimen authored
379 <%= form.input :title %> # => :label => "Choose a title...", :hint => "Choose a good title for you post."
380 <%= form.input :body %> # => :label => "Write something...", :hint => "Write something inspiring here."
381 <%= form.input :section %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
382 <% end %>
a8e2f2e @justinfrench fix README examples missing form.x prefix for buttons and inputs
authored
383 <% form.buttons do %>
743b26b @yabawock Revert "Reverting two i18n patches pulled in from the rails3 branch w…
yabawock authored
384 <%= form.commit_button %> # => "Create my %{model}"
4aca8cd @grimen New I18n-features:
grimen authored
385 <% end %>
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
386 <% end %>
387 </pre>
388
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to…
grimen authored
389 *4. Localized titles (a.k.a. legends):*
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset…
grimen authored
390
17f6668 @justinfrench Revert "This reverts commit 440bd2d8da117acdbca57fa199c115caefcd87c0."
authored
391 _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._
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset…
grimen authored
392
393 <pre>
394 <% semantic_form_for @post do |form| %>
17f6668 @justinfrench Revert "This reverts commit 440bd2d8da117acdbca57fa199c115caefcd87c0."
authored
395 <% form.inputs :post_details do %> # => :title => "Post details"
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset…
grimen authored
396 # ...
397 <% end %>
398 # ...
399 <% end %>
400 </pre>
401
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to…
grimen authored
402 *5. Override I18n settings:*
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
403
404 <pre>
405 <% semantic_form_for @post do |form| %>
a8e2f2e @justinfrench fix README examples missing form.x prefix for buttons and inputs
authored
406 <% form.inputs do %>
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset…
grimen authored
407 <%= form.input :title %> # => :label => "Choose a title...", :hint => "Choose a good title for you post."
408 <%= form.input :body, :hint => false %> # => :label => "Write something..."
409 <%= form.input :section, :label => 'Some section' %> # => :label => 'Some section'
410 <% end %>
a8e2f2e @justinfrench fix README examples missing form.x prefix for buttons and inputs
authored
411 <% form.buttons do %>
4aca8cd @grimen New I18n-features:
grimen authored
412 <%= form.commit_button :dummie %> # => "Launch!"
413 <% end %>
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
414 <% end %>
415 </pre>
416
417 If I18n-lookups is disabled, i.e.:
418
419 <pre>
420 Formtastic::SemanticFormBuilder.i18n_lookups_by_default = false
421 </pre>
422
423 ...then you can enable I18n within the forms instead:
424
425 <pre>
426 <% semantic_form_for @post do |form| %>
a8e2f2e @justinfrench fix README examples missing form.x prefix for buttons and inputs
authored
427 <% form.inputs do %>
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset…
grimen authored
428 <%= form.input :title, :label => true %> # => :label => "Choose a title..."
429 <%= form.input :body, :label => true %> # => :label => "Write something..."
430 <%= form.input :section, :label => true %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
431 <% end %>
a8e2f2e @justinfrench fix README examples missing form.x prefix for buttons and inputs
authored
432 <% form.buttons do %>
4b1ba5f @dbackeus Updated expected commit_button text in README.
dbackeus authored
433 <%= form.commit_button true %> # => "Update %{model}" (if we are in edit that is...)
4aca8cd @grimen New I18n-features:
grimen authored
434 <% end %>
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
435 <% end %>
436 </pre>
437
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to…
grimen authored
438 *6. Advanced I18n lookups*
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
439
440 For more flexible forms; Formtastic find translations using a bottom-up approach taking the following variables in account:
441
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset…
grimen authored
442 * @MODEL@, e.g. "post"
443 * @ACTION@, e.g. "edit"
4aca8cd @grimen New I18n-features:
grimen authored
444 * @KEY/ATTRIBUTE@, e.g. "title", :my_custom_key, ...
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
445
446 ...in the following order:
447
6688887 @grimen More README-polishing.
grimen authored
448 1. @formtastic.{titles,labels,hints,actions}.MODEL.ACTION.ATTRIBUTE@ - by model and action
449 2. @formtastic.{titles,labels,hints,actions}.MODEL.ATTRIBUTE@ - by model
450 3. @formtastic.{titles,labels,hints,actions}.ATTRIBUTE@ - global default
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
451
452 ...which means that you can define translations like this:
453
454 <pre>
455 en:
456 formtastic:
457 labels:
458 title: "Title" # Default global value
459 article:
460 body: "Article content"
461 post:
462 new:
463 title: "Choose a title..."
464 body: "Write something..."
465 edit:
466 title: "Edit title"
467 body: "Edit body"
468 </pre>
469
4aca8cd @grimen New I18n-features:
grimen authored
470 Values for @labels@/@hints@/@actions@ are can take values: @String@ (explicit value), @Symbol@ (i18n-lookup-key relative to the current "type", e.g. actions:), @true@ (force I18n lookup), @false@ (force no I18n lookup). Titles (legends) can only take: @String@ and @Symbol@ - true/false have no meaning.
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset…
grimen authored
471
71ef99f @justinfrench nuked the configuration copy/paste from the README, linked to the gen…
authored
472
c4ebcef * added semantic_errors method with specs
Wojciech Wnętrzak authored
473 h2. Semantic errors
474
475 You can show errors on base (by default) and any other attribute just passing it name to semantic_errors method:
476
477 <pre>
478 <% semantic_form_for @post do |form| %>
479 <%= form.semantic_errors :state %>
480 <% end %>
481 </pre>
482
483
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
484 h2. ValidationReflection plugin
485
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to…
grimen authored
486 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).
5a39443 @justinfrench bulking up the documentation and readme with the different inputs ava…
authored
487
488
71ef99f @justinfrench nuked the configuration copy/paste from the README, linked to the gen…
authored
489 h2. Configuration
5a39443 @justinfrench bulking up the documentation and readme with the different inputs ava…
authored
490
3340c53 @justinfrench Remove Rails 2 stuff from README
authored
491 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/generators/formtastic/templates/formtastic.rb
3a32b4a @josevalim Updated README with new configuration options.
josevalim authored
492
5a39443 @justinfrench bulking up the documentation and readme with the different inputs ava…
authored
493
fef3288 @grimen Added documentation for the form generator in README, and showing som…
grimen authored
494 h2. Form Generator
495
5f3d7a6 @justinfrench updated the generator docs in README to reflect both Rails 3 and 2
authored
496 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 stuff.
fef3288 @grimen Added documentation for the form generator in README, and showing som…
grimen authored
497
5f3d7a6 @justinfrench updated the generator docs in README to reflect both Rails 3 and 2
authored
498 h3. Basic usage
499
fef3288 @grimen Added documentation for the form generator in README, and showing som…
grimen authored
500 <pre>
5f3d7a6 @justinfrench updated the generator docs in README to reflect both Rails 3 and 2
authored
501 $ rails generate formtastic:form ModelName
502 </pre>
fef3288 @grimen Added documentation for the form generator in README, and showing som…
grimen authored
503
5f3d7a6 @justinfrench updated the generator docs in README to reflect both Rails 3 and 2
authored
504 The results are something like this, with the ERB code printed out to the terminal
505
506 <pre>
507 $ rails generate formtastic:form Post
508 # ---------------------------------------------------------
509 # GENERATED FORMTASTIC CODE
510 # ---------------------------------------------------------
511
512 <% f.inputs do %>
513 <%= f.input :title, :label => 'Title' %>
514 <%= f.input :body, :label => 'Body' %>
515 <%= f.input :published, :label => 'Published' %>
516 <% end %>
517
518 # ---------------------------------------------------------
519 Copied to clipboard - just paste it!
fef3288 @grimen Added documentation for the form generator in README, and showing som…
grimen authored
520 </pre>
521
5f3d7a6 @justinfrench updated the generator docs in README to reflect both Rails 3 and 2
authored
522 h3. Generating a partial with @--partial@
523
524 You can also ask Formtastic to *generate a partial* with the @--partial@ option, placing it in the correct location inside your @app/views@ directory:
fef3288 @grimen Added documentation for the form generator in README, and showing som…
grimen authored
525
526 <pre>
f7e2c87 @rahult Changed formastic to formtastic in README
rahult authored
527 $ rails generate formtastic:form Post --partial
fef3288 @grimen Added documentation for the form generator in README, and showing som…
grimen authored
528 exists app/views/posts
529 create app/views/posts/_form.html.erb
530 </pre>
531
5f3d7a6 @justinfrench updated the generator docs in README to reflect both Rails 3 and 2
authored
532 h3. Specifying HAML instead of ERB with @--haml@
3f58f3a @justinfrench README update for --controller option form generator
authored
533
534 <pre>
f7e2c87 @rahult Changed formastic to formtastic in README
rahult authored
535 $ rails generate formtastic:form Post --haml
3f58f3a @justinfrench README update for --controller option form generator
authored
536 exists app/views/admin/posts
537 create app/views/admin/posts/_form.html.haml
538 </pre>
539
5f3d7a6 @justinfrench updated the generator docs in README to reflect both Rails 3 and 2
authored
540 h3. Specifying controller namespace with @--controller@
3f58f3a @justinfrench README update for --controller option form generator
authored
541
542 <pre>
f7e2c87 @rahult Changed formastic to formtastic in README
rahult authored
543 $ rails generate formtastic:form Post --partial --controller admin/posts
3f58f3a @justinfrench README update for --controller option form generator
authored
544 exists app/views/admin/posts
545 create app/views/admin/posts/_form.html.erb
546 </pre>
547
fef3288 @grimen Added documentation for the form generator in README, and showing som…
grimen authored
548
ce7da5e @justinfrench added the builder config to the config template and quick documentati…
authored
549 h2. Custom Inputs
550
551 If you want to add your own input types to encapsulate your own logic or interface patterns, you can do so by subclassing SemanticFormBuilder and configuring Formtastic to use your custom builder class.
552
553 @Formtastic::SemanticFormHelper.builder = MyCustomBuilder@
554
28bb57f @paneq Resolves http://github.com/justinfrench/formtastic/issues/#issue/409
paneq authored
555 Be aware that you should either set the options on custom builder or require it after setting options on formtastic default builder.
ce7da5e @justinfrench added the builder config to the config template and quick documentati…
authored
556
28bb57f @paneq Resolves http://github.com/justinfrench/formtastic/issues/#issue/409
paneq authored
557 <pre>
153f4e8 @justinfrench Merge branch 'master' of http://github.com/paneq/formtastic into pane…
authored
558 # OK
559 Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
560 require 'formtastic/my_custom_builder'
561 Formtastic::SemanticFormHelper.builder = Formtastic::MyCustomBuilder
562
563 # OK
564 require 'formtastic/my_custom_builder'
565 Formtastic::SemanticFormHelper.builder = Formtastic::MyCustomBuilder
566 Formtastic::MyCustomBuilder.i18n_lookups_by_default = true
567
568 # WRONG!
569 require 'formtastic/my_custom_builder'
570 Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
571 Formtastic::SemanticFormHelper.builder = Formtastic::MyCustomBuilder
28bb57f @paneq Resolves http://github.com/justinfrench/formtastic/issues/#issue/409
paneq authored
572 </pre>
3f58f3a @justinfrench README update for --controller option form generator
authored
573
5f3d7a6 @justinfrench updated the generator docs in README to reflect both Rails 3 and 2
authored
574
2d2d813 @yabawock More intelligent way to html_escape labels and hints (GH-299)
yabawock authored
575 h2. Security
ce7da5e @justinfrench added the builder config to the config template and quick documentati…
authored
576
2d2d813 @yabawock More intelligent way to html_escape labels and hints (GH-299)
yabawock authored
577 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:
578
579 Formtastic::SemanticFormBuilder.escape_html_entities_in_hints_and_labels = false
3f58f3a @justinfrench README update for --controller option form generator
authored
580
581
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
582 h2. Dependencies
dcf8beb Initial Commit
Justin French authored
583
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
584 There are none, but...
dcf8beb Initial Commit
Justin French authored
585
e9f27cf @grimen The most tiny README-update ever. =)
grimen authored
586 * 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).
1fcc068 @grimen An effort to make the README somewhat more readable.
grimen authored
587 * if you want to use the @:country@ input, you'll need to install the "iso-3166-country-select plugin":http://github.com/rails/iso-3166-country-select (or any other country_select plugin with the same API).
588 * "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.
dcf8beb Initial Commit
Justin French authored
589
0b370ba @justinfrench Renamed input_field_set() to just inputs() and added a shorthand vers…
authored
590
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
591 h2. Compatibility
0b370ba @justinfrench Renamed input_field_set() to just inputs() and added a shorthand vers…
authored
592
3340c53 @justinfrench Remove Rails 2 stuff from README
authored
593 * We're only testing Formtastic with the latest Rails stable release. Patches are welcome to allow backwards compatibility with previous versions of Rails, of course, but we've dropped support for Rails 2. Formtastic 1.x is compatible with Rails 2, and is being maintained for bug fixes only. See the README in the "1.2-stable branch":https://github.com/justinfrench/formtastic/tree/1.2-stable.
594 * Formtastic, much like Rails, is very ActiveRecord-centric. Many people are using Formtastic successfully with other ActiveModel-like ORMs and classes (DataMapper, MongoMapper, Mongoid, Authlogic, Devise...) but we're not guaranteeing full compatibility at this stage. Patches are welcome.
4036e74 @justinfrench pruning and cleaning up the README, it's been a while
authored
595
61d0056 @justinfrench * updated the status to reflect that this is a release candidate
authored
596
2079c59 @justinfrench added a section about contributing to README
authored
597 h2. How to contribute
598
533c086 @justinfrench added a section to the README on getting a dev environment up and run…
authored
599 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.
2079c59 @justinfrench added a section about contributing to README
authored
600
601 Please also keep your commits *atomic* so that they are more likely to apply cleanly. That means that each commit should contain the smallest possible logical change. Don't commit two features at once, don't update the gemspec at the same time you add a feature, don't fix a whole bunch of whitespace in a file at the same time you change a few lines, etc, etc.
602
603 For significant changes, you may wish to discuss your idea on the Formtastic Google group before coding to ensure that your change is likely to be accepted. Formtastic relies heavily on i18n, so if you're unsure of the impact this has on your changes, please discuss them with the group.
604
533c086 @justinfrench added a section to the README on getting a dev environment up and run…
authored
605 See below for installation of a development environment.
606
607
259a98c @justinfrench updated heading in README
authored
608 h2. Maintainers & Contributors
83b9eb1 @justinfrench updated the contributors list
authored
609
644d100 @yabawock Fix typo in Readme
yabawock authored
610 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.
619ce6c @justinfrench added Grimen to the README, updated contributors list, etc
authored
611
612 @git shortlog -n -s --no-merges@
2d4a72b @justinfrench big update to the README
authored
613
5af0311 @justinfrench updated the README to pimp the google group more
authored
614
90282e3 @justinfrench added twitter account to the readme
authored
615 h2. Google Group, Twitter, etc
5af0311 @justinfrench updated the README to pimp the google group more
authored
616
617 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.
618
90282e3 @justinfrench added twitter account to the readme
authored
619 You can also "follow @formtastic on Twitter":http://twitter.com/formtastic for announcements, tutorials and awesome Formtastic links.
620
5af0311 @justinfrench updated the README to pimp the google group more
authored
621
ba3ce05 @justinfrench updated the README a little with contributors and some other busy work
authored
622 h2. Project Info
623
1fcc068 @grimen An effort to make the README somewhat more readable.
grimen authored
624 Formtastic is hosted on Github: "http://github.com/justinfrench/formtastic":http://github.com/justinfrench/formtastic, where your contributions, forkings, comments and feedback are greatly welcomed.
ba3ce05 @justinfrench updated the README a little with contributors and some other busy work
authored
625
626
ebe4e51 @justinfrench updated the README to reflect the new gem versions and other compatib…
authored
627 Copyright (c) 2007-2010 Justin French, released under the MIT license.
Something went wrong with that request. Please try again.