Skip to content
Newer
Older
100644 554 lines (397 sloc) 22.3 KB
420b4ce @justinfrench sick of updating the README with every version bump :)
authored Apr 22, 2009
1 h1. Formtastic
dcf8beb Initial Commit
Justin French authored Apr 7, 2008
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
09d957d textilized the README so that it looks pretty pretty on GitHub
Justin French authored Apr 29, 2008
5 h2. The Story
dcf8beb Initial Commit
Justin French authored Apr 7, 2008
6
2d4a72b @justinfrench big update to the README
authored Feb 16, 2009
7 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 Apr 7, 2008
8
09d957d textilized the README so that it looks pretty pretty on GitHub
Justin French authored Apr 29, 2008
9 <pre>
7e3874a @justinfrench trying to fix README formatting of <'s at the start of lines
authored Aug 13, 2008
10 <% semantic_form_for @article do |form| %>
353618e @markmansour Extending Formtastic can be done by overriding the semantic_form_buil…
markmansour authored Jan 13, 2009
11
0b370ba @justinfrench Renamed input_field_set() to just inputs() and added a shorthand vers…
authored Jan 6, 2009
12 <% form.inputs :name => "Basic" do %>
353618e @markmansour Extending Formtastic can be done by overriding the semantic_form_buil…
markmansour authored Jan 13, 2009
13 <%= form.input :title %>
14 <%= form.input :body %>
1db292f @sprsquish update README to reflect association attribute changes
sprsquish authored Feb 28, 2009
15 <%= form.input :section %>
16 <%= form.input :publication_state, :as => :radio %>
9997ce6 @josevalim Added more information about inputs :for in README.
josevalim authored Mar 7, 2009
17 <%= form.input :category %>
353618e @markmansour Extending Formtastic can be done by overriding the semantic_form_buil…
markmansour authored Jan 13, 2009
18 <%= form.input :allow_comments, :label => "Allow commenting on this article" %>
19 <% end %>
20
0b370ba @justinfrench Renamed input_field_set() to just inputs() and added a shorthand vers…
authored Jan 6, 2009
21 <% form.inputs :name => "Advanced" do %>
353618e @markmansour Extending Formtastic can be done by overriding the semantic_form_buil…
markmansour authored Jan 13, 2009
22 <%= 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 Aug 14, 2008
23 <%= form.input :extract, :required => false %>
24 <%= form.input :description, :required => false %>
353618e @markmansour Extending Formtastic can be done by overriding the semantic_form_buil…
markmansour authored Jan 13, 2009
25 <%= form.input :url_title, :required => false %>
7e3874a @justinfrench trying to fix README formatting of <'s at the start of lines
authored Aug 14, 2008
26 <% end %>
27
05ae54d @josevalim Fixed nested attributes example in README
josevalim authored Mar 22, 2009
28 <% form.inputs :name => "Author", :for => :author do |author_form| %>
29 <%= author_form.input :first_name %>
30 <%= author_form.input :last_name %>
9997ce6 @josevalim Added more information about inputs :for in README.
josevalim authored Mar 7, 2009
31 <% end %>
32
353618e @markmansour Extending Formtastic can be done by overriding the semantic_form_buil…
markmansour authored Jan 13, 2009
33 <% form.buttons do %>
34 <%= form.commit_button %>
7e3874a @justinfrench trying to fix README formatting of <'s at the start of lines
authored Aug 14, 2008
35 <% end %>
09d957d textilized the README so that it looks pretty pretty on GitHub
Justin French authored Apr 29, 2008
36
dcf8beb Initial Commit
Justin French authored Apr 7, 2008
37 <% end %>
09d957d textilized the README so that it looks pretty pretty on GitHub
Justin French authored Apr 29, 2008
38 </pre>
39
6734cfd @justinfrench sme typos and cleanups in the readme
authored Jul 21, 2008
40 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 Apr 7, 2008
41
42
9af5cc8 @justinfrench Big update and re-organization of the README:
authored Feb 28, 2009
43 h2. It's better than _SomeOtherFormBuilder_ because...
44
6688887 @grimen More README-polishing.
grimen authored Oct 25, 2009
45 * 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.
46 * 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.
47 * it's Rails 2.3-ready (including nested forms).
f02b136 @justinfrench rearranged and beefed up the 'it's better than...' README section
authored Mar 1, 2009
48 * it has internationalization (I18n)!
6688887 @grimen More README-polishing.
grimen authored Oct 25, 2009
49 * 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.
50 * there's heaps of elements, id and class attributes for you to hook in your CSS and JS.
51 * it handles real world stuff like inline hints, inline error messages & help text.
52 * 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).
53 * it's got absolutely awesome spec coverage.
54 * 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 Feb 28, 2009
55
56
15e0bd9 updated the README a little to match last night's slides
Justin French authored May 30, 2008
57 h2. Why?
58
6688887 @grimen More README-polishing.
grimen authored Oct 25, 2009
59 * web apps = lots of forms.
60 * forms are so friggin' boring to code.
61 * semantically rich & accessible forms really are possible.
62 * the "V" is way behind the "M" and "C" in Rails' MVC – it's the ugly sibling.
63 * best practices and common patterns have to start somewhere.
64 * i need a challenge.
dcf8beb Initial Commit
Justin French authored Apr 7, 2008
65
66
15e0bd9 updated the README a little to match last night's slides
Justin French authored May 29, 2008
67 h2. Opinions
68
6688887 @grimen More README-polishing.
grimen authored Oct 25, 2009
69 * it should be easier to do things the right way than the wrong way.
70 * sometimes _more mark-up_ is better.
71 * elements and attribute hooks are _gold_ for stylesheet authors.
72 * 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 May 29, 2008
73
dcf8beb Initial Commit
Justin French authored Apr 7, 2008
74
3dd6455 @justinfrench Link to RDoc URL in README
authored Jul 3, 2009
75 h2. Documentation
76
77 RDoc documentation _should_ be automatically generated after each commit and made available on the "rdoc.info website":http://rdoc.info/projects/justinfrench/formtastic.
78
79
c89e985 @justinfrench updating README with gem/plugin installation instructions
authored Mar 8, 2009
80 h2. Installation
81
1fcc068 @grimen An effort to make the README somewhat more readable.
grimen authored Oct 25, 2009
82 The gem is hosted on gemcutter, so *if you haven't already*, add it as a gem source:
c89e985 @justinfrench updating README with gem/plugin installation instructions
authored Mar 8, 2009
83
84 <pre>
2bf5b23 @justinfrench updated README to reflect gemcutter gem source
authored Oct 21, 2009
85 sudo gem sources -a http://gemcutter.org/
c89e985 @justinfrench updating README with gem/plugin installation instructions
authored Mar 8, 2009
86 </pre>
87
1fcc068 @grimen An effort to make the README somewhat more readable.
grimen authored Oct 25, 2009
88 Then install the Formtastic gem:
c89e985 @justinfrench updating README with gem/plugin installation instructions
authored Mar 8, 2009
89
90 <pre>
2bf5b23 @justinfrench updated README to reflect gemcutter gem source
authored Oct 21, 2009
91 sudo gem install formtastic
c89e985 @justinfrench updating README with gem/plugin installation instructions
authored Mar 8, 2009
92 </pre>
93
6ae6675 @justinfrench adding config.gem instructions to README, thanks Tom White
authored Jan 7, 2010
94 And add it to your environment.rb configuration as a gem dependency:
95
96 <pre>
97 config.gem 'formtastic'
98 </pre>
99
2bf5b23 @justinfrench updated README to reflect gemcutter gem source
authored Oct 21, 2009
100 Optionally, run @./script/generate formtastic@ to copy the following files into your app:
fc29eaa @justinfrench Combined the "formtastic_config" and "formtastic_stylesheets" generat…
authored Oct 11, 2009
101
1fcc068 @grimen An effort to make the README somewhat more readable.
grimen authored Oct 25, 2009
102 * @config/initializers/formtastic.rb@ - a commented out Formtastic config initializer
103 * @public/stylesheets/formtastic.css@
104 * @public/stylesheets/formtastic_changes.css@
c89e985 @justinfrench updating README with gem/plugin installation instructions
authored Mar 8, 2009
105
1fcc068 @grimen An effort to make the README somewhat more readable.
grimen authored Oct 25, 2009
106 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:
c89e985 @justinfrench updating README with gem/plugin installation instructions
authored Mar 8, 2009
107
5c1ce48 @justinfrench moved the stylesheets stuff up with installation
authored Oct 21, 2009
108 <pre>
109 <%= stylesheet_link_tag "formtastic" %>
110 <%= stylesheet_link_tag "formtastic_changes" %>
111 </pre>
2526d2c @justinfrench Going back to generators instead of Rake tasks for copying stylesheet…
authored Oct 11, 2009
112
9af5cc8 @justinfrench Big update and re-organization of the README:
authored Feb 28, 2009
113 h2. Usage
114
115 Forms are really boring to code... you want to get onto the good stuff as fast as possible.
116
6688887 @grimen More README-polishing.
grimen authored Oct 25, 2009
117 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 Feb 28, 2009
118
119 <pre>
120 <% semantic_form_for @user do |form| %>
121 <%= form.inputs %>
122 <%= form.buttons %>
123 <% end %>
124 </pre>
125
126 If you 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@:
127
128 <pre>
129 <% semantic_form_for @user do |form| %>
130 <%= form.inputs :title, :body, :section, :categories, :created_at %>
131 <%= form.buttons :commit %>
132 <% end %>
133 </pre>
134
6688887 @grimen More README-polishing.
grimen authored Oct 25, 2009
135 If you 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 Feb 28, 2009
136
137 <pre>
138 <% semantic_form_for @post do |form| %>
139 <% form.inputs do %>
140 <%= form.input :title %>
141 <%= form.input :body %>
142 <%= form.input :section, :as => :radio %>
143 <%= form.input :categories %>
144 <%= form.input :created_at, :as => :string %>
145 <% end %>
146 <% form.buttons do %>
147 <%= form.commit_button %>
148 <% end %>
149 <% end %>
150 </pre>
151
a45853c @justinfrench small README typo
authored Apr 19, 2009
152 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 Feb 28, 2009
153
154 <pre>
155 <% semantic_form_for @post do |form| %>
17f6668 @justinfrench Revert "This reverts commit 440bd2d."
authored Nov 21, 2009
156 <% form.inputs "Basic", :id => "basic" do %>
9af5cc8 @justinfrench Big update and re-organization of the README:
authored Feb 28, 2009
157 <%= form.input :title %>
158 <%= form.input :body %>
159 <% end %>
160 <% form.inputs :name => "Advanced Options", :id => "advanced" do %>
161 <%= form.input :slug, :label => "URL Title", :hint => "Created automatically if left blank", :required => false %>
162 <%= form.input :section, :as => :radio %>
163 <%= form.input :user, :label => "Author", :label_method => :full_name, %>
164 <%= form.input :categories, :required => false %>
165 <%= form.input :created_at, :as => :string, :label => "Publication Date", :required => false %>
166 <% end %>
167 <% form.buttons do %>
168 <%= form.commit_button %>
169 <% end %>
170 <% end %>
171 </pre>
172
9997ce6 @josevalim Added more information about inputs :for in README.
josevalim authored Mar 7, 2009
173 Nested forms (Rails 2.3) are also supported. You can do it in the Rails way:
9af5cc8 @justinfrench Big update and re-organization of the README:
authored Feb 28, 2009
174
175 <pre>
05ae54d @josevalim Fixed nested attributes example in README
josevalim authored Mar 22, 2009
176 <% semantic_form_for @post do |form| %>
177 <%= form.inputs :title, :body, :created_at %>
41a6754 @josevalim Another README fix.
josevalim authored Mar 24, 2009
178 <% form.semantic_fields_for :author do |author| %>
1fcc068 @grimen An effort to make the README somewhat more readable.
grimen authored Oct 25, 2009
179 <%= author.inputs :first_name, :last_name, :name => "Author" %>
41a6754 @josevalim Another README fix.
josevalim authored Mar 23, 2009
180 <% end %>
05ae54d @josevalim Fixed nested attributes example in README
josevalim authored Mar 22, 2009
181 <%= form.buttons %>
9997ce6 @josevalim Added more information about inputs :for in README.
josevalim authored Mar 7, 2009
182 <% end %>
183 </pre>
184
6fd1bd2 @justinfrench improving the documentation in README
authored Apr 19, 2009
185 Or the Formtastic way with the @:for@ option:
9997ce6 @josevalim Added more information about inputs :for in README.
josevalim authored Mar 7, 2009
186
187 <pre>
05ae54d @josevalim Fixed nested attributes example in README
josevalim authored Mar 22, 2009
188 <% semantic_form_for @post do |form| %>
189 <%= form.inputs :title, :body, :created_at %>
190 <%= form.inputs :first_name, :last_name, :for => :author, :name => "Author" %>
191 <%= form.buttons %>
9af5cc8 @justinfrench Big update and re-organization of the README:
authored Feb 28, 2009
192 <% end %>
193 </pre>
194
1fcc068 @grimen An effort to make the README somewhat more readable.
grimen authored Oct 25, 2009
195 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 Mar 24, 2009
196
197 <pre>
198 <% semantic_form_for @post do |form| %>
199 <%= form.inputs %>
200 <%= form.inputs :name => 'Category #%i', :for => :categories %>
201 <%= form.buttons %>
202 <% end %>
203 </pre>
204
6fd1bd2 @justinfrench improving the documentation in README
authored Apr 19, 2009
205
1fcc068 @grimen An effort to make the README somewhat more readable.
grimen authored Oct 25, 2009
206 Customize HTML attributes for any input using the @:input_html@ option. Typically his 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 Apr 19, 2009
207
208 <pre>
209 <% semantic_form_for @post do |form| %>
210 <%= form.input :title, :input_html => { :size => 60 } %>
211 <%= form.input :body, :input_html => { :class => 'autogrow' } %>
212 <%= form.input :created_at, :input_html => { :disabled => true } %>
213 <%= form.buttons %>
214 <% end %>
215 </pre>
216
217 The same can be done for buttons with the @:button_html@ option:
218
219 <pre>
220 <% semantic_form_for @post do |form| %>
221 ...
222 <% form.buttons do %>
223 <%= form.commit_button :button_html => { :class => "primary" } %>
224 <% end %>
225 <% end %>
226 </pre>
227
1fcc068 @grimen An effort to make the README somewhat more readable.
grimen authored Oct 25, 2009
228 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"@)
229
6fd1bd2 @justinfrench improving the documentation in README
authored Apr 19, 2009
230 <pre>
231 <% semantic_form_for @post do |form| %>
232 <%= form.input :title, :wrapper_html => { :class => "important" } %>
233 <%= form.input :body %>
234 <%= form.input :description, :wrapper_html => { :style => "display:none;" } %>
235 ...
236 <% end %>
237 </pre>
238
239
5a39443 @justinfrench bulking up the documentation and readme with the different inputs ava…
authored Jun 28, 2008
240 h2. The Available Inputs
241
d9a06fe @grimen README: Last set of polishing moves for now.
grimen authored Oct 25, 2009
242 The Formtastic input types:
243
8577c18 @grimen More README-readability polishing.
grimen authored Oct 25, 2009
244 * @:select@ - a select menu. Default for ActiveRecord associations: @belongs_to@, @has_many@, and @has_and_belongs_to_many@.
245 * @:check_boxes@ - a set of check_box inputs. Alternative to @:select@ for ActiveRecord-associations: @has_many@, and @has_and_belongs_to_many@.
246 * @:radio@ - a set of radio inputs. Alternative to @:select@ for ActiveRecord-associations: @belongs_to@.
247 * @:time_zone@ - a select input. Default for column types: @:string@ with name matching @"time_zone"@.
248 * @:password@ - a password input. Default for column types: @:string@ with name matching @"password"@.
249 * @:text@ - a textarea. Default for column types: @:text@.
250 * @:date@ - a date select. Default for column types: @:date@.
251 * @:datetime@ - a date and time select. Default for column types: @:datetime@ and @:timestamp@.
252 * @:time@ - a time select. Default for column types: @:time@.
253 * @:boolean@ - a checkbox. Default for column types: @:boolean@.
254 * @:string@ - a text field. Default for column types: @:string@.
255 * @:numeric@ - a text field (just like string). Default for column types: @:integer@, @:float@, and @:decimal@.
256 * @: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.
257 * @:country@ - a select menu of country names. Default for column types: :string with name @"country"@ - requires a *country_select* plugin to be installed.
6688887 @grimen More README-polishing.
grimen authored Oct 25, 2009
258 * @:hidden@ - a hidden field. Creates a hidden field (added for compatibility).
259
260 The documentation is pretty good for each of these (what it does, what the output is, what the options are, etc.) so go check it out.
5a39443 @justinfrench bulking up the documentation and readme with the different inputs ava…
authored Jun 28, 2008
261
06ff25d @lardawge Added section clarifying label lookup order.
lardawge authored Dec 10, 2009
262 h2. Delegation for label lookups
263
264 Formtastic decides which label to use in the following order:
265
266 <pre>
267 1. :label # :label => "Choose Title"
268 2. Formtastic i18n # if either :label => true || i18n_lookups_by_default = true (see Internationalization)
269 3. Activerecord i18n # if localization file found for the given attribute
270 4. label_str_method # if nothing provided this defaults to :humanize but can be set to a custom method
271 </pre>
272
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored Aug 3, 2009
273 h2. Internationalization (I18n)
274
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to…
grimen authored Oct 25, 2009
275 h3. Basic Localization
71ef99f @justinfrench nuked the configuration copy/paste from the README, linked to the gen…
authored Oct 21, 2009
276
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to…
grimen authored Oct 25, 2009
277 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 Aug 2, 2009
278
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset…
grimen authored Sep 16, 2009
279 Basic localization (labels only, with ActiveRecord):
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored Aug 2, 2009
280
281 <pre>
282 <% semantic_form_for @post do |form| %>
283 <%= form.input :title %> # => :label => I18n.t('activerecord.attributes.user.title') or 'Title'
284 <%= form.input :body %> # => :label => I18n.t('activerecord.attributes.user.body') or 'Body'
285 <%= form.input :section %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
286 <% end %>
287 </pre>
288
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to…
grimen authored Oct 25, 2009
289 *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?
290
291 h3. Enhanced Localization (Formtastic I18n API)
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored Aug 2, 2009
292
d9a06fe @grimen README: Last set of polishing moves for now.
grimen authored Oct 25, 2009
293 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 Aug 2, 2009
294
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to…
grimen authored Oct 25, 2009
295 *1. Enable I18n lookups by default (@config/initializers/formtastic.rb@):*
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored Aug 2, 2009
296
297 <pre>
298 Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
299 </pre>
300
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to…
grimen authored Oct 25, 2009
301 *2. Add some cool label-translations/variants (@config/locale/en.yml@):*
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored Aug 2, 2009
302
303 <pre>
304 en:
305 formtastic:
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset…
grimen authored Sep 16, 2009
306 titles:
307 post_details: "Post details"
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored Aug 2, 2009
308 labels:
309 post:
310 title: "Choose a title..."
311 body: "Write something..."
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset…
grimen authored Sep 16, 2009
312 edit:
313 title: "Edit title"
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored Aug 2, 2009
314 hints:
315 post:
316 title: "Choose a good title for you post."
317 body: "Write something inspiring here."
4aca8cd @grimen New I18n-features:
grimen authored Oct 24, 2009
318 actions:
319 create: "Create my {{model}}"
320 update: "Save changes"
321 dummie: "Launch!"
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored Aug 2, 2009
322 </pre>
323
324 *Note:* We are using English here still, but you get the point.
325
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to…
grimen authored Oct 25, 2009
326 *3. ...and now you'll get:*
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored Aug 2, 2009
327
328 <pre>
4aca8cd @grimen New I18n-features:
grimen authored Oct 24, 2009
329 <% semantic_form_for Post.new do |form| %>
a8e2f2e @justinfrench fix README examples missing form.x prefix for buttons and inputs
authored Nov 10, 2009
330 <% form.inputs do %>
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset…
grimen authored Sep 16, 2009
331 <%= form.input :title %> # => :label => "Choose a title...", :hint => "Choose a good title for you post."
332 <%= form.input :body %> # => :label => "Write something...", :hint => "Write something inspiring here."
333 <%= form.input :section %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
334 <% end %>
a8e2f2e @justinfrench fix README examples missing form.x prefix for buttons and inputs
authored Nov 10, 2009
335 <% form.buttons do %>
4aca8cd @grimen New I18n-features:
grimen authored Oct 24, 2009
336 <%= form.commit_button %> # => "Create my {{model}}"
337 <% end %>
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored Aug 2, 2009
338 <% end %>
339 </pre>
340
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to…
grimen authored Oct 25, 2009
341 *4. Localized titles (a.k.a. legends):*
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset…
grimen authored Sep 16, 2009
342
17f6668 @justinfrench Revert "This reverts commit 440bd2d."
authored Nov 21, 2009
343 _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 Sep 16, 2009
344
345 <pre>
346 <% semantic_form_for @post do |form| %>
17f6668 @justinfrench Revert "This reverts commit 440bd2d."
authored Nov 21, 2009
347 <% form.inputs :post_details do %> # => :title => "Post details"
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset…
grimen authored Sep 16, 2009
348 # ...
349 <% end %>
350 # ...
351 <% end %>
352 </pre>
353
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to…
grimen authored Oct 25, 2009
354 *5. Override I18n settings:*
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored Aug 2, 2009
355
356 <pre>
357 <% semantic_form_for @post do |form| %>
a8e2f2e @justinfrench fix README examples missing form.x prefix for buttons and inputs
authored Nov 10, 2009
358 <% form.inputs do %>
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset…
grimen authored Sep 16, 2009
359 <%= form.input :title %> # => :label => "Choose a title...", :hint => "Choose a good title for you post."
360 <%= form.input :body, :hint => false %> # => :label => "Write something..."
361 <%= form.input :section, :label => 'Some section' %> # => :label => 'Some section'
362 <% end %>
a8e2f2e @justinfrench fix README examples missing form.x prefix for buttons and inputs
authored Nov 10, 2009
363 <% form.buttons do %>
4aca8cd @grimen New I18n-features:
grimen authored Oct 24, 2009
364 <%= form.commit_button :dummie %> # => "Launch!"
365 <% end %>
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored Aug 2, 2009
366 <% end %>
367 </pre>
368
369 If I18n-lookups is disabled, i.e.:
370
371 <pre>
372 Formtastic::SemanticFormBuilder.i18n_lookups_by_default = false
373 </pre>
374
375 ...then you can enable I18n within the forms instead:
376
377 <pre>
378 <% semantic_form_for @post do |form| %>
a8e2f2e @justinfrench fix README examples missing form.x prefix for buttons and inputs
authored Nov 10, 2009
379 <% form.inputs do %>
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset…
grimen authored Sep 16, 2009
380 <%= form.input :title, :label => true %> # => :label => "Choose a title..."
381 <%= form.input :body, :label => true %> # => :label => "Write something..."
382 <%= form.input :section, :label => true %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
383 <% end %>
a8e2f2e @justinfrench fix README examples missing form.x prefix for buttons and inputs
authored Nov 10, 2009
384 <% form.buttons do %>
4aca8cd @grimen New I18n-features:
grimen authored Oct 24, 2009
385 <%= form.commit_button true %> # => "Save changes" (if we are in edit that is...)
386 <% end %>
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored Aug 2, 2009
387 <% end %>
388 </pre>
389
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to…
grimen authored Oct 25, 2009
390 *6. Advanced I18n lookups*
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored Aug 2, 2009
391
392 For more flexible forms; Formtastic find translations using a bottom-up approach taking the following variables in account:
393
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset…
grimen authored Sep 16, 2009
394 * @MODEL@, e.g. "post"
395 * @ACTION@, e.g. "edit"
4aca8cd @grimen New I18n-features:
grimen authored Oct 24, 2009
396 * @KEY/ATTRIBUTE@, e.g. "title", :my_custom_key, ...
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored Aug 2, 2009
397
398 ...in the following order:
399
6688887 @grimen More README-polishing.
grimen authored Oct 25, 2009
400 1. @formtastic.{titles,labels,hints,actions}.MODEL.ACTION.ATTRIBUTE@ - by model and action
401 2. @formtastic.{titles,labels,hints,actions}.MODEL.ATTRIBUTE@ - by model
402 3. @formtastic.{titles,labels,hints,actions}.ATTRIBUTE@ - global default
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored Aug 2, 2009
403
404 ...which means that you can define translations like this:
405
406 <pre>
407 en:
408 formtastic:
409 labels:
410 title: "Title" # Default global value
411 article:
412 body: "Article content"
413 post:
414 new:
415 title: "Choose a title..."
416 body: "Write something..."
417 edit:
418 title: "Edit title"
419 body: "Edit body"
420 </pre>
421
4aca8cd @grimen New I18n-features:
grimen authored Oct 24, 2009
422 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 Sep 16, 2009
423
71ef99f @justinfrench nuked the configuration copy/paste from the README, linked to the gen…
authored Oct 21, 2009
424
c4ebcef * added semantic_errors method with specs
Wojciech Wnętrzak authored Dec 3, 2009
425 h2. Semantic errors
426
427 You can show errors on base (by default) and any other attribute just passing it name to semantic_errors method:
428
429 <pre>
430 <% semantic_form_for @post do |form| %>
431 <%= form.semantic_errors :state %>
432 <% end %>
433 </pre>
434
435
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored Aug 2, 2009
436 h2. ValidationReflection plugin
437
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to…
grimen authored Oct 25, 2009
438 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 Jun 28, 2008
439
440
71ef99f @justinfrench nuked the configuration copy/paste from the README, linked to the gen…
authored Oct 21, 2009
441 h2. Configuration
5a39443 @justinfrench bulking up the documentation and readme with the different inputs ava…
authored Jun 28, 2008
442
1fcc068 @grimen An effort to make the README somewhat more readable.
grimen authored Oct 25, 2009
443 Run @./script/generate formtastic@ 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 Mar 4, 2009
444
5a39443 @justinfrench bulking up the documentation and readme with the different inputs ava…
authored Jun 28, 2008
445
fef3288 @grimen Added documentation for the form generator in README, and showing som…
grimen authored Nov 19, 2009
446 h2. Form Generator
447
448 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 you stuff. This is how you use it:
449
450 *Alt. 1: Generate in terminal:*
451
452 <pre>
453 $ ./script/generate form Post
454 # ---------------------------------------------------------
455 # GENERATED FORMTASTIC CODE
456 # ---------------------------------------------------------
457
e57b9d1 @grimen Form generator: |f| is a better default for |form|. Also works better…
grimen authored Dec 17, 2009
458 <% f.inputs do %>
459 <%= f.input :title, :label => 'Title' %>
460 <%= f.input :body, :label => 'Body' %>
461 <%= f.input :published, :label => 'Published' %>
fef3288 @grimen Added documentation for the form generator in README, and showing som…
grimen authored Nov 19, 2009
462 <% end %>
463
464 # ---------------------------------------------------------
465 Copied to clipboard - just paste it!
466 </pre>
467
468 *Alt. 2: Generate partial:*
469
470 <pre>
471 $ ./script/generate form Post --partial
472 exists app/views/posts
473 create app/views/posts/_form.html.erb
474 </pre>
475
3f58f3a @justinfrench README update for --controller option form generator
authored Dec 3, 2009
476 To generate *HAML* markup, just add the @--haml@ as argument:
477
478 <pre>
479 $ ./script/generate form Post --haml
480 exists app/views/admin/posts
481 create app/views/admin/posts/_form.html.haml
482 </pre>
483
484 To specify the controller in a namespace (eg admin/posts instead of posts), use the --controller argument:
485
486 <pre>
487 $ ./script/generate form Post --partial --controller admin/posts
488 exists app/views/admin/posts
489 create app/views/admin/posts/_form.html.erb
490 </pre>
491
fef3288 @grimen Added documentation for the form generator in README, and showing som…
grimen authored Nov 19, 2009
492
ce7da5e @justinfrench added the builder config to the config template and quick documentati…
authored Nov 10, 2009
493 h2. Custom Inputs
494
495 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.
496
497 @Formtastic::SemanticFormHelper.builder = MyCustomBuilder@
498
499
3f58f3a @justinfrench README update for --controller option form generator
authored Dec 2, 2009
500
501
09d957d textilized the README so that it looks pretty pretty on GitHub
Justin French authored Apr 29, 2008
502 h2. Status
dcf8beb Initial Commit
Justin French authored Apr 7, 2008
503
6688887 @grimen More README-polishing.
grimen authored Oct 25, 2009
504 Formtastic has been in active development for about a year. We've just recently jumped to an 0.9 version number, signaling that we consider this a 1.0 release candidate, and that the API won't change significantly for the 1.x series.
c5d02e6 @justinfrench link to the wiki for the roadmap to 1.0 in README
authored Feb 16, 2009
505
dcf8beb Initial Commit
Justin French authored Apr 7, 2008
506
9af5cc8 @justinfrench Big update and re-organization of the README:
authored Feb 28, 2009
507 h2. Dependencies
dcf8beb Initial Commit
Justin French authored Apr 7, 2008
508
9af5cc8 @justinfrench Big update and re-organization of the README:
authored Feb 28, 2009
509 There are none, but...
dcf8beb Initial Commit
Justin French authored Apr 7, 2008
510
e9f27cf @grimen The most tiny README-update ever. =)
grimen authored Nov 28, 2009
511 * 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 Oct 25, 2009
512 * 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).
513 * "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 Apr 7, 2008
514
0b370ba @justinfrench Renamed input_field_set() to just inputs() and added a shorthand vers…
authored Jan 6, 2009
515
9af5cc8 @justinfrench Big update and re-organization of the README:
authored Feb 28, 2009
516 h2. Compatibility
0b370ba @justinfrench Renamed input_field_set() to just inputs() and added a shorthand vers…
authored Jan 6, 2009
517
d7fff76 @justinfrench updated compatability guidelines
authored Nov 10, 2009
518 I'm only testing Formtastic with the latest Rails 2.4.x stable release, and it should be fine under Rails 2.3.x as well (including nested forms). Patches are welcome to allow backwards compatibility, but I don't have the energy!
0b370ba @justinfrench Renamed input_field_set() to just inputs() and added a shorthand vers…
authored Jan 6, 2009
519
67a799f @grimen Made method_required? respect the :if conditional on validates_presen…
grimen authored Sep 3, 2009
520 h2. Got TextMate?
521
6688887 @grimen More README-polishing.
grimen authored Oct 25, 2009
522 Well...there's a TextMate-bundle in town, dedicated to make usage of Formtastic in the "TextMate":http://macromates.com/ editor even more of a breeze:
67a799f @grimen Made method_required? respect the :if conditional on validates_presen…
grimen authored Sep 3, 2009
523
524 "Formtastic.tmbundle":http://github.com/grimen/formtastic_tmbundle
2d4a72b @justinfrench big update to the README
authored Feb 16, 2009
525
61d0056 @justinfrench * updated the status to reflect that this is a release candidate
authored Oct 21, 2009
526
2079c59 @justinfrench added a section about contributing to README
authored Jan 2, 2010
527 h2. How to contribute
528
529 *Before you send a pull request*, 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.
530
531 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.
532
533 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.
534
535
259a98c @justinfrench updated heading in README
authored Jan 2, 2010
536 h2. Maintainers & Contributors
83b9eb1 @justinfrench updated the contributors list
authored Apr 2, 2009
537
4ac2f58 @justinfrench we now have over 40 contributors
authored Jan 2, 2010
538 Formtastic is maintained by "Justin French":http://justinfrench.com, "José Valim":http://github.com/josevalim and "Jonas Grimfelt":http://github.com/grimen, but it wouldn't be as awesome as it is today without help from over 40 contributors.
619ce6c @justinfrench added Grimen to the README, updated contributors list, etc
authored Nov 10, 2009
539
540 @git shortlog -n -s --no-merges@
2d4a72b @justinfrench big update to the README
authored Feb 16, 2009
541
5af0311 @justinfrench updated the README to pimp the google group more
authored Apr 2, 2009
542
7a84a73 @justinfrench README heading tweak
authored Nov 10, 2009
543 h2. Google Group
5af0311 @justinfrench updated the README to pimp the google group more
authored Apr 2, 2009
544
545 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.
546
547
ba3ce05 @justinfrench updated the README a little with contributors and some other busy work
authored Jun 27, 2008
548 h2. Project Info
549
1fcc068 @grimen An effort to make the README somewhat more readable.
grimen authored Oct 25, 2009
550 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 Jun 27, 2008
551
552
25d0c7a @justinfrench fleshed out a 'roadmap to 1.0' in the README
authored Dec 8, 2008
553 Copyright (c) 2007-2008 Justin French, released under the MIT license.
Something went wrong with that request. Please try again.