Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 591 lines (425 sloc) 26.275 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
09d957d textilized the README so that it looks pretty pretty on GitHub
Justin French authored
5 h2. The Story
dcf8beb Initial Commit
Justin French authored
6
2d4a72b @justinfrench big update to the README
authored
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
8
09d957d textilized the README so that it looks pretty pretty on GitHub
Justin French authored
9 <pre>
7e3874a @justinfrench trying to fix README formatting of <'s at the start of lines
authored
10 <% semantic_form_for @article do |form| %>
353618e @markmansour Extending Formtastic can be done by overriding the semantic_form_builder...
markmansour authored
11
0b370ba @justinfrench Renamed input_field_set() to just inputs() and added a shorthand version...
authored
12 <% form.inputs :name => "Basic" do %>
353618e @markmansour Extending Formtastic can be done by overriding the semantic_form_builder...
markmansour authored
13 <%= form.input :title %>
14 <%= form.input :body %>
1db292f @sprsquish update README to reflect association attribute changes
sprsquish authored
15 <%= form.input :section %>
16 <%= form.input :publication_state, :as => :radio %>
9997ce6 @josevalim Added more information about inputs :for in README.
josevalim authored
17 <%= form.input :category %>
353618e @markmansour Extending Formtastic can be done by overriding the semantic_form_builder...
markmansour authored
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 version...
authored
21 <% form.inputs :name => "Advanced" do %>
353618e @markmansour Extending Formtastic can be done by overriding the semantic_form_builder...
markmansour authored
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
23 <%= form.input :extract, :required => false %>
24 <%= form.input :description, :required => false %>
353618e @markmansour Extending Formtastic can be done by overriding the semantic_form_builder...
markmansour authored
25 <%= form.input :url_title, :required => false %>
7e3874a @justinfrench trying to fix README formatting of <'s at the start of lines
authored
26 <% end %>
27
05ae54d @josevalim Fixed nested attributes example in README
josevalim authored
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
31 <% end %>
32
353618e @markmansour Extending Formtastic can be done by overriding the semantic_form_builder...
markmansour authored
33 <% form.buttons do %>
34 <%= form.commit_button %>
7e3874a @justinfrench trying to fix README formatting of <'s at the start of lines
authored
35 <% end %>
09d957d textilized the README so that it looks pretty pretty on GitHub
Justin French authored
36
dcf8beb Initial Commit
Justin French authored
37 <% end %>
09d957d textilized the README so that it looks pretty pretty on GitHub
Justin French authored
38 </pre>
39
6734cfd @justinfrench sme typos and cleanups in the readme
authored
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
41
42
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
43 h2. It's better than _SomeOtherFormBuilder_ because...
44
6688887 @grimen More README-polishing.
grimen authored
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
48 * it has internationalization (I18n)!
6688887 @grimen More README-polishing.
grimen authored
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
55
56
15e0bd9 updated the README a little to match last night's slides
Justin French authored
57 h2. Why?
58
6688887 @grimen More README-polishing.
grimen authored
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
65
66
15e0bd9 updated the README a little to match last night's slides
Justin French authored
67 h2. Opinions
68
6688887 @grimen More README-polishing.
grimen authored
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
73
dcf8beb Initial Commit
Justin French authored
74
3dd6455 @justinfrench Link to RDoc URL in README
authored
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
4036e74 @justinfrench pruning and cleaning up the README, it's been a while
authored
80 h2. A Note About Rails 3 Support
81
82 Formtastic 1.0 will only support the latest stable Rails 2.x. We're maintaining a rails3 branch which aims to provide both Rails 2.x and 3.x support, which is targeted for the 1.1 release soon after 1.0, around the same time Rails 3.0 ships.
83
84 If you have a Rails 3 project and would like to use Formtastic's rails3 branch, bundler provides you with the ability to do this easily. Just add Formtastic as a git dependency in your Gemfile with the :branch option:
85
86 <pre>
87 gem 'formtastic', :git => "http://github.com/justinfrench/formtastic.git", :branch => "rails3"
88 </pre>
89
90 Please be aware that Rails 3 is still under heavy development (even in the later betas), as is Formtastic, so our rails3 branch is very much "on the edge", just like Rails. if you find issues, compatibility issues with Rails 2 or 3, please report an issue on Github.
91
92
93 h2. Installation under Rails 2.x
c89e985 @justinfrench updating README with gem/plugin installation instructions
authored
94
6291113 @justinfrench README udpated to mention --pre and ditch the gemcutter guff
authored
95 Install the Formtastic gem:
c89e985 @justinfrench updating README with gem/plugin installation instructions
authored
96
97 <pre>
6291113 @justinfrench README udpated to mention --pre and ditch the gemcutter guff
authored
98 sudo gem install formtastic
c89e985 @justinfrench updating README with gem/plugin installation instructions
authored
99 </pre>
100
6291113 @justinfrench README udpated to mention --pre and ditch the gemcutter guff
authored
101 Or try the 1.0.0.beta2:
c89e985 @justinfrench updating README with gem/plugin installation instructions
authored
102
103 <pre>
6291113 @justinfrench README udpated to mention --pre and ditch the gemcutter guff
authored
104 sudo gem install formtastic --pre
c89e985 @justinfrench updating README with gem/plugin installation instructions
authored
105 </pre>
106
6ae6675 @justinfrench adding config.gem instructions to README, thanks Tom White
authored
107 And add it to your environment.rb configuration as a gem dependency:
108
109 <pre>
110 config.gem 'formtastic'
111 </pre>
112
2bf5b23 @justinfrench updated README to reflect gemcutter gem source
authored
113 Optionally, run @./script/generate formtastic@ to copy the following files into your app:
fc29eaa @justinfrench Combined the "formtastic_config" and "formtastic_stylesheets" generators...
authored
114
b4fc852 @justinfrench Revert "generated config file is now called formtastic_config.rb rather ...
authored
115 * @config/initializers/formtastic.rb@ - a commented out Formtastic config initializer
1fcc068 @grimen An effort to make the README somewhat more readable.
grimen authored
116 * @public/stylesheets/formtastic.css@
117 * @public/stylesheets/formtastic_changes.css@
c89e985 @justinfrench updating README with gem/plugin installation instructions
authored
118
127a6b9 @justinfrench Added a Formtastic::LayoutHelper with formtastic_stylesheets so that we ...
authored
119 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
120
5c1ce48 @justinfrench moved the stylesheets stuff up with installation
authored
121 <pre>
127a6b9 @justinfrench Added a Formtastic::LayoutHelper with formtastic_stylesheets so that we ...
authored
122 <head>
123 ...
124 <%= formtastic_stylesheet_link_tag %>
125 ...
126 </head>
5c1ce48 @justinfrench moved the stylesheets stuff up with installation
authored
127 </pre>
2526d2c @justinfrench Going back to generators instead of Rake tasks for copying stylesheets a...
authored
128
4036e74 @justinfrench pruning and cleaning up the README, it's been a while
authored
129
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
130 h2. Usage
131
132 Forms are really boring to code... you want to get onto the good stuff as fast as possible.
133
6688887 @grimen More README-polishing.
grimen authored
134 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
135
136 <pre>
137 <% semantic_form_for @user do |form| %>
138 <%= form.inputs %>
139 <%= form.buttons %>
140 <% end %>
141 </pre>
142
143 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@:
144
145 <pre>
146 <% semantic_form_for @user do |form| %>
147 <%= form.inputs :title, :body, :section, :categories, :created_at %>
148 <%= form.buttons :commit %>
149 <% end %>
150 </pre>
151
6688887 @grimen More README-polishing.
grimen authored
152 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
153
154 <pre>
155 <% semantic_form_for @post do |form| %>
156 <% form.inputs do %>
157 <%= form.input :title %>
158 <%= form.input :body %>
159 <%= form.input :section, :as => :radio %>
160 <%= form.input :categories %>
161 <%= form.input :created_at, :as => :string %>
162 <% end %>
163 <% form.buttons do %>
164 <%= form.commit_button %>
165 <% end %>
166 <% end %>
167 </pre>
168
a45853c @justinfrench small README typo
authored
169 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
170
171 <pre>
172 <% semantic_form_for @post do |form| %>
17f6668 @justinfrench Revert "This reverts commit 440bd2d8da117acdbca57fa199c115caefcd87c0."
authored
173 <% form.inputs "Basic", :id => "basic" do %>
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
174 <%= form.input :title %>
175 <%= form.input :body %>
176 <% end %>
177 <% form.inputs :name => "Advanced Options", :id => "advanced" do %>
178 <%= form.input :slug, :label => "URL Title", :hint => "Created automatically if left blank", :required => false %>
179 <%= form.input :section, :as => :radio %>
180 <%= form.input :user, :label => "Author", :label_method => :full_name, %>
181 <%= form.input :categories, :required => false %>
182 <%= form.input :created_at, :as => :string, :label => "Publication Date", :required => false %>
183 <% end %>
184 <% form.buttons do %>
185 <%= form.commit_button %>
186 <% end %>
187 <% end %>
188 </pre>
189
4db9cfe @justinfrench tweaked README to include accepts_nested_attributes_for mention
authored
190 Nested forms (Rails 2.3) are also supported (don't forget your models need to be setup correctly with accepts_nested_attributes_for – search the Rails docs). You can do it in the Rails way:
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
191
192 <pre>
05ae54d @josevalim Fixed nested attributes example in README
josevalim authored
193 <% semantic_form_for @post do |form| %>
194 <%= form.inputs :title, :body, :created_at %>
41a6754 @josevalim Another README fix.
josevalim authored
195 <% form.semantic_fields_for :author do |author| %>
1fcc068 @grimen An effort to make the README somewhat more readable.
grimen authored
196 <%= author.inputs :first_name, :last_name, :name => "Author" %>
41a6754 @josevalim Another README fix.
josevalim authored
197 <% end %>
05ae54d @josevalim Fixed nested attributes example in README
josevalim authored
198 <%= form.buttons %>
9997ce6 @josevalim Added more information about inputs :for in README.
josevalim authored
199 <% end %>
200 </pre>
201
6fd1bd2 @justinfrench improving the documentation in README
authored
202 Or the Formtastic way with the @:for@ option:
9997ce6 @josevalim Added more information about inputs :for in README.
josevalim authored
203
204 <pre>
05ae54d @josevalim Fixed nested attributes example in README
josevalim authored
205 <% semantic_form_for @post do |form| %>
206 <%= form.inputs :title, :body, :created_at %>
207 <%= form.inputs :first_name, :last_name, :for => :author, :name => "Author" %>
208 <%= form.buttons %>
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
209 <% end %>
210 </pre>
211
1fcc068 @grimen An effort to make the README somewhat more readable.
grimen authored
212 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
213
214 <pre>
215 <% semantic_form_for @post do |form| %>
216 <%= form.inputs %>
217 <%= form.inputs :name => 'Category #%i', :for => :categories %>
218 <%= form.buttons %>
219 <% end %>
220 </pre>
221
6fd1bd2 @justinfrench improving the documentation in README
authored
222
29133e1 @dougireton Fixed minor typo in README Usage section.
dougireton authored
223 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
224
225 <pre>
226 <% semantic_form_for @post do |form| %>
227 <%= form.input :title, :input_html => { :size => 60 } %>
228 <%= form.input :body, :input_html => { :class => 'autogrow' } %>
229 <%= form.input :created_at, :input_html => { :disabled => true } %>
230 <%= form.buttons %>
231 <% end %>
232 </pre>
233
234 The same can be done for buttons with the @:button_html@ option:
235
236 <pre>
237 <% semantic_form_for @post do |form| %>
238 ...
239 <% form.buttons do %>
240 <%= form.commit_button :button_html => { :class => "primary" } %>
241 <% end %>
242 <% end %>
243 </pre>
244
1fcc068 @grimen An effort to make the README somewhat more readable.
grimen authored
245 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"@)
246
6fd1bd2 @justinfrench improving the documentation in README
authored
247 <pre>
248 <% semantic_form_for @post do |form| %>
249 <%= form.input :title, :wrapper_html => { :class => "important" } %>
250 <%= form.input :body %>
251 <%= form.input :description, :wrapper_html => { :style => "display:none;" } %>
252 ...
253 <% end %>
254 </pre>
255
a92cf7c @justinfrench added documentation for :collection option, resolves #181
authored
256 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:
257
258 <pre>
259 f.input :authors, :as => :check_boxes, :collection => User.find(:all, :order => "last_name ASC")
260 f.input :authors, :as => :check_boxes, :collection => current_user.company.users.active
261 f.input :authors, :as => :check_boxes, :collection => [@justin, @kate]
262 f.input :authors, :as => :check_boxes, :collection => ["Justin", "Kate", "Amelia", "Gus", "Meg"]
263 f.input :author, :as => :select, :collection => Author.find(:all)
264 f.input :author, :as => :select, :collection => { @justin.name => @justin.id, @kate.name => @kate.id }
265 f.input :author, :as => :select, :collection => ["Justin", "Kate", "Amelia", "Gus", "Meg"]
266 f.input :author, :as => :radio, :collection => User.find(:all)
267 f.input :author, :as => :radio, :collection => [@justin, @kate]
268 f.input :author, :as => :radio, :collection => { @justin.name => @justin.id, @kate.name => @kate.id }
269 f.input :author, :as => :radio, :collection => ["Justin", "Kate", "Amelia", "Gus", "Meg"]
270 f.input :admin, :as => :radio, :collection => ["Yes!", "No"]
271 </pre>
272
6fd1bd2 @justinfrench improving the documentation in README
authored
273
5a39443 @justinfrench bulking up the documentation and readme with the different inputs availa...
authored
274 h2. The Available Inputs
275
d9a06fe @grimen README: Last set of polishing moves for now.
grimen authored
276 The Formtastic input types:
277
8577c18 @grimen More README-readability polishing.
grimen authored
278 * @:select@ - a select menu. Default for ActiveRecord associations: @belongs_to@, @has_many@, and @has_and_belongs_to_many@.
279 * @:check_boxes@ - a set of check_box inputs. Alternative to @:select@ for ActiveRecord-associations: @has_many@, and @has_and_belongs_to_many@.
280 * @:radio@ - a set of radio inputs. Alternative to @:select@ for ActiveRecord-associations: @belongs_to@.
281 * @:time_zone@ - a select input. Default for column types: @:string@ with name matching @"time_zone"@.
282 * @:password@ - a password input. Default for column types: @:string@ with name matching @"password"@.
283 * @:text@ - a textarea. Default for column types: @:text@.
284 * @:date@ - a date select. Default for column types: @:date@.
285 * @:datetime@ - a date and time select. Default for column types: @:datetime@ and @:timestamp@.
286 * @:time@ - a time select. Default for column types: @:time@.
287 * @:boolean@ - a checkbox. Default for column types: @:boolean@.
288 * @:string@ - a text field. Default for column types: @:string@.
289 * @:numeric@ - a text field (just like string). Default for column types: @:integer@, @:float@, and @:decimal@.
290 * @: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.
291 * @: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
292 * @:hidden@ - a hidden field. Creates a hidden field (added for compatibility).
293
fd23ef4 @justinfrench tiny README tweak
authored
294 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.
295
5a39443 @justinfrench bulking up the documentation and readme with the different inputs availa...
authored
296
06ff25d @lardawge Added section clarifying label lookup order.
lardawge authored
297 h2. Delegation for label lookups
298
299 Formtastic decides which label to use in the following order:
300
301 <pre>
302 1. :label # :label => "Choose Title"
303 2. Formtastic i18n # if either :label => true || i18n_lookups_by_default = true (see Internationalization)
304 3. Activerecord i18n # if localization file found for the given attribute
305 4. label_str_method # if nothing provided this defaults to :humanize but can be set to a custom method
306 </pre>
307
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
308 h2. Internationalization (I18n)
309
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to re...
grimen authored
310 h3. Basic Localization
71ef99f @justinfrench nuked the configuration copy/paste from the README, linked to the genera...
authored
311
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to re...
grimen authored
312 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
313
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset ti...
grimen authored
314 Basic localization (labels only, with ActiveRecord):
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
315
316 <pre>
317 <% semantic_form_for @post do |form| %>
318 <%= form.input :title %> # => :label => I18n.t('activerecord.attributes.user.title') or 'Title'
319 <%= form.input :body %> # => :label => I18n.t('activerecord.attributes.user.body') or 'Body'
320 <%= form.input :section %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
321 <% end %>
322 </pre>
323
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to re...
grimen authored
324 *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?
325
326 h3. Enhanced Localization (Formtastic I18n API)
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
327
d9a06fe @grimen README: Last set of polishing moves for now.
grimen authored
328 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
329
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to re...
grimen authored
330 *1. Enable I18n lookups by default (@config/initializers/formtastic.rb@):*
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
331
332 <pre>
333 Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
334 </pre>
335
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to re...
grimen authored
336 *2. Add some cool label-translations/variants (@config/locale/en.yml@):*
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
337
338 <pre>
339 en:
340 formtastic:
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset ti...
grimen authored
341 titles:
342 post_details: "Post details"
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
343 labels:
344 post:
345 title: "Choose a title..."
346 body: "Write something..."
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset ti...
grimen authored
347 edit:
348 title: "Edit title"
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
349 hints:
350 post:
351 title: "Choose a good title for you post."
352 body: "Write something inspiring here."
4aca8cd @grimen New I18n-features:
grimen authored
353 actions:
1469b53 @justinfrench Reverting two i18n patches pulled in from the rails3 branch which are no...
authored
354 create: "Create my {{model}}"
4aca8cd @grimen New I18n-features:
grimen authored
355 update: "Save changes"
356 dummie: "Launch!"
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
357 </pre>
358
359 *Note:* We are using English here still, but you get the point.
360
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to re...
grimen authored
361 *3. ...and now you'll get:*
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
362
363 <pre>
4aca8cd @grimen New I18n-features:
grimen authored
364 <% semantic_form_for Post.new do |form| %>
a8e2f2e @justinfrench fix README examples missing form.x prefix for buttons and inputs
authored
365 <% form.inputs do %>
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset ti...
grimen authored
366 <%= form.input :title %> # => :label => "Choose a title...", :hint => "Choose a good title for you post."
367 <%= form.input :body %> # => :label => "Write something...", :hint => "Write something inspiring here."
368 <%= form.input :section %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
369 <% end %>
a8e2f2e @justinfrench fix README examples missing form.x prefix for buttons and inputs
authored
370 <% form.buttons do %>
1469b53 @justinfrench Reverting two i18n patches pulled in from the rails3 branch which are no...
authored
371 <%= form.commit_button %> # => "Create my {{model}}"
4aca8cd @grimen New I18n-features:
grimen authored
372 <% end %>
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
373 <% end %>
374 </pre>
375
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to re...
grimen authored
376 *4. Localized titles (a.k.a. legends):*
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset ti...
grimen authored
377
17f6668 @justinfrench Revert "This reverts commit 440bd2d8da117acdbca57fa199c115caefcd87c0."
authored
378 _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 ti...
grimen authored
379
380 <pre>
381 <% semantic_form_for @post do |form| %>
17f6668 @justinfrench Revert "This reverts commit 440bd2d8da117acdbca57fa199c115caefcd87c0."
authored
382 <% form.inputs :post_details do %> # => :title => "Post details"
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset ti...
grimen authored
383 # ...
384 <% end %>
385 # ...
386 <% end %>
387 </pre>
388
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to re...
grimen authored
389 *5. Override I18n settings:*
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
390
391 <pre>
392 <% semantic_form_for @post do |form| %>
a8e2f2e @justinfrench fix README examples missing form.x prefix for buttons and inputs
authored
393 <% form.inputs do %>
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset ti...
grimen authored
394 <%= form.input :title %> # => :label => "Choose a title...", :hint => "Choose a good title for you post."
395 <%= form.input :body, :hint => false %> # => :label => "Write something..."
396 <%= form.input :section, :label => 'Some section' %> # => :label => 'Some section'
397 <% end %>
a8e2f2e @justinfrench fix README examples missing form.x prefix for buttons and inputs
authored
398 <% form.buttons do %>
4aca8cd @grimen New I18n-features:
grimen authored
399 <%= form.commit_button :dummie %> # => "Launch!"
400 <% end %>
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
401 <% end %>
402 </pre>
403
404 If I18n-lookups is disabled, i.e.:
405
406 <pre>
407 Formtastic::SemanticFormBuilder.i18n_lookups_by_default = false
408 </pre>
409
410 ...then you can enable I18n within the forms instead:
411
412 <pre>
413 <% semantic_form_for @post do |form| %>
a8e2f2e @justinfrench fix README examples missing form.x prefix for buttons and inputs
authored
414 <% form.inputs do %>
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset ti...
grimen authored
415 <%= form.input :title, :label => true %> # => :label => "Choose a title..."
416 <%= form.input :body, :label => true %> # => :label => "Write something..."
417 <%= form.input :section, :label => true %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
418 <% end %>
a8e2f2e @justinfrench fix README examples missing form.x prefix for buttons and inputs
authored
419 <% form.buttons do %>
4aca8cd @grimen New I18n-features:
grimen authored
420 <%= form.commit_button true %> # => "Save changes" (if we are in edit that is...)
421 <% end %>
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
422 <% end %>
423 </pre>
424
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to re...
grimen authored
425 *6. Advanced I18n lookups*
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
426
427 For more flexible forms; Formtastic find translations using a bottom-up approach taking the following variables in account:
428
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset ti...
grimen authored
429 * @MODEL@, e.g. "post"
430 * @ACTION@, e.g. "edit"
4aca8cd @grimen New I18n-features:
grimen authored
431 * @KEY/ATTRIBUTE@, e.g. "title", :my_custom_key, ...
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
432
433 ...in the following order:
434
6688887 @grimen More README-polishing.
grimen authored
435 1. @formtastic.{titles,labels,hints,actions}.MODEL.ACTION.ATTRIBUTE@ - by model and action
436 2. @formtastic.{titles,labels,hints,actions}.MODEL.ATTRIBUTE@ - by model
437 3. @formtastic.{titles,labels,hints,actions}.ATTRIBUTE@ - global default
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
438
439 ...which means that you can define translations like this:
440
441 <pre>
442 en:
443 formtastic:
444 labels:
445 title: "Title" # Default global value
446 article:
447 body: "Article content"
448 post:
449 new:
450 title: "Choose a title..."
451 body: "Write something..."
452 edit:
453 title: "Edit title"
454 body: "Edit body"
455 </pre>
456
4aca8cd @grimen New I18n-features:
grimen authored
457 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 ti...
grimen authored
458
71ef99f @justinfrench nuked the configuration copy/paste from the README, linked to the genera...
authored
459
c4ebcef * added semantic_errors method with specs
Wojciech Wnętrzak authored
460 h2. Semantic errors
461
462 You can show errors on base (by default) and any other attribute just passing it name to semantic_errors method:
463
464 <pre>
465 <% semantic_form_for @post do |form| %>
466 <%= form.semantic_errors :state %>
467 <% end %>
468 </pre>
469
470
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
471 h2. ValidationReflection plugin
472
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to re...
grimen authored
473 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 availa...
authored
474
475
71ef99f @justinfrench nuked the configuration copy/paste from the README, linked to the genera...
authored
476 h2. Configuration
5a39443 @justinfrench bulking up the documentation and readme with the different inputs availa...
authored
477
1fcc068 @grimen An effort to make the README somewhat more readable.
grimen authored
478 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
479
5a39443 @justinfrench bulking up the documentation and readme with the different inputs availa...
authored
480
fef3288 @grimen Added documentation for the form generator in README, and showing some i...
grimen authored
481 h2. Form Generator
482
483 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:
484
485 *Alt. 1: Generate in terminal:*
486
487 <pre>
488 $ ./script/generate form Post
489 # ---------------------------------------------------------
490 # GENERATED FORMTASTIC CODE
491 # ---------------------------------------------------------
492
e57b9d1 @grimen Form generator: |f| is a better default for |form|. Also works better wi...
grimen authored
493 <% f.inputs do %>
494 <%= f.input :title, :label => 'Title' %>
495 <%= f.input :body, :label => 'Body' %>
496 <%= f.input :published, :label => 'Published' %>
fef3288 @grimen Added documentation for the form generator in README, and showing some i...
grimen authored
497 <% end %>
498
499 # ---------------------------------------------------------
500 Copied to clipboard - just paste it!
501 </pre>
502
503 *Alt. 2: Generate partial:*
504
505 <pre>
506 $ ./script/generate form Post --partial
507 exists app/views/posts
508 create app/views/posts/_form.html.erb
509 </pre>
510
3f58f3a @justinfrench README update for --controller option form generator
authored
511 To generate *HAML* markup, just add the @--haml@ as argument:
512
513 <pre>
514 $ ./script/generate form Post --haml
515 exists app/views/admin/posts
516 create app/views/admin/posts/_form.html.haml
517 </pre>
518
519 To specify the controller in a namespace (eg admin/posts instead of posts), use the --controller argument:
520
521 <pre>
522 $ ./script/generate form Post --partial --controller admin/posts
523 exists app/views/admin/posts
524 create app/views/admin/posts/_form.html.erb
525 </pre>
526
fef3288 @grimen Added documentation for the form generator in README, and showing some i...
grimen authored
527
ce7da5e @justinfrench added the builder config to the config template and quick documentation ...
authored
528 h2. Custom Inputs
529
530 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.
531
532 @Formtastic::SemanticFormHelper.builder = MyCustomBuilder@
533
2d2d813 @yabawock More intelligent way to html_escape labels and hints (GH-299)
yabawock authored
534 h2. Security
ce7da5e @justinfrench added the builder config to the config template and quick documentation ...
authored
535
2d2d813 @yabawock More intelligent way to html_escape labels and hints (GH-299)
yabawock authored
536 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:
537
538 Formtastic::SemanticFormBuilder.escape_html_entities_in_hints_and_labels = false
3f58f3a @justinfrench README update for --controller option form generator
authored
539
540
4036e74 @justinfrench pruning and cleaning up the README, it's been a while
authored
541 h2. Focus
dcf8beb Initial Commit
Justin French authored
542
4036e74 @justinfrench pruning and cleaning up the README, it's been a while
authored
543 Formtastic is close to shipping a 1.0 release candidate after more than a year of active development. 1.0 will be compatible with Rails 2, and this is our top priority right now. We've also been working hard on a Rails 2 *and* 3 compatible version in the rails3 branch, targeting a 1.1 release shortly after Rails 3.0 ships.
544
545 There's heaps more we want to do, but we have to do this first.
c5d02e6 @justinfrench link to the wiki for the roadmap to 1.0 in README
authored
546
dcf8beb Initial Commit
Justin French authored
547
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
548 h2. Dependencies
dcf8beb Initial Commit
Justin French authored
549
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
550 There are none, but...
dcf8beb Initial Commit
Justin French authored
551
e9f27cf @grimen The most tiny README-update ever. =)
grimen authored
552 * 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
553 * 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).
554 * "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
555
0b370ba @justinfrench Renamed input_field_set() to just inputs() and added a shorthand version...
authored
556
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
557 h2. Compatibility
0b370ba @justinfrench Renamed input_field_set() to just inputs() and added a shorthand version...
authored
558
4036e74 @justinfrench pruning and cleaning up the README, it's been a while
authored
559 * We're only testing Formtastic with the latest Rails 2.x stable release. Patches are welcome to allow backwards compatibility with older versions of Rails, of course.
560 * Development of a Rails 2 *and* 3 compatible version of Formtastic is underway in the rails3 branch, targeting a Formtastic 1.1 release shortly after Rails 3.0 ships.
561 * Formtastic, much like Rails 2, is very ActiveRecord-centric. Many people are using Formtastic (especially the rails3 branch) successfully with other ActiveModel-like ORMs and classes (DataMapper, MongoMapper, Mongoid, Authlogic, Devise...) but we're not guaranteeing anything at this stage. Patches are welcome, but it's not our core focus right now. Shipping a solid 1.0 and Rails 3 compatible 1.1 is.
562
61d0056 @justinfrench * updated the status to reflect that this is a release candidate
authored
563
2079c59 @justinfrench added a section about contributing to README
authored
564 h2. How to contribute
565
4036e74 @justinfrench pruning and cleaning up the README, it's been a while
authored
566 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 an issue on GH for us to discuss your changes. Pull requests tend to get lost.
2079c59 @justinfrench added a section about contributing to README
authored
567
568 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.
569
570 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.
571
572
259a98c @justinfrench updated heading in README
authored
573 h2. Maintainers & Contributors
83b9eb1 @justinfrench updated the contributors list
authored
574
4036e74 @justinfrench pruning and cleaning up the README, it's been a while
authored
575 Formtastic is maintained by "Justin French":http://github.com/justinfrench, "Morton Jonuscha":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
576
577 @git shortlog -n -s --no-merges@
2d4a72b @justinfrench big update to the README
authored
578
5af0311 @justinfrench updated the README to pimp the google group more
authored
579
7a84a73 @justinfrench README heading tweak
authored
580 h2. Google Group
5af0311 @justinfrench updated the README to pimp the google group more
authored
581
582 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.
583
584
ba3ce05 @justinfrench updated the README a little with contributors and some other busy work
authored
585 h2. Project Info
586
1fcc068 @grimen An effort to make the README somewhat more readable.
grimen authored
587 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
588
589
25d0c7a @justinfrench fleshed out a 'roadmap to 1.0' in the README
authored
590 Copyright (c) 2007-2008 Justin French, released under the MIT license.
Something went wrong with that request. Please try again.