Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 605 lines (450 sloc) 26.211 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
dc5857b @justinfrench moved compatibility note in README further up
authored
7
8 h2. Compatibility
9
22a9af1 @justinfrench prep README for 2.0
authored
10 * Formtastic 2.0 is Rails 3.x compatible only
11 * Formtastic 1.x is compatible with both Rails 2 and 3, and is being maintained for bug fixes in the the "1.2-stable branch":https://github.com/justinfrench/formtastic/tree/1.2-stable. View the README in that branch for installation instructions, etc.
dc5857b @justinfrench moved compatibility note in README further up
authored
12 * Formtastic, much like Rails, is very ActiveRecord-centric. Many are successfully using other ActiveModel-like ORMs and objects (DataMapper, MongoMapper, Mongoid, Authlogic, Devise...) but we're not guaranteeing full compatibility at this stage. Patches are welcome!
13
14
09d957d textilized the README so that it looks pretty pretty on GitHub
Justin French authored
15 h2. The Story
dcf8beb Initial Commit
Justin French authored
16
2d4a72b @justinfrench big update to the README
authored
17 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
18
09d957d textilized the README so that it looks pretty pretty on GitHub
Justin French authored
19 <pre>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
20 <%= semantic_form_for @article do |form| %>
353618e @markmansour Extending Formtastic can be done by overriding the semantic_form_builder...
markmansour authored
21
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
22 <%= form.inputs :name => "Basic" do %>
353618e @markmansour Extending Formtastic can be done by overriding the semantic_form_builder...
markmansour authored
23 <%= form.input :title %>
24 <%= form.input :body %>
1db292f @sprsquish update README to reflect association attribute changes
sprsquish authored
25 <%= form.input :section %>
26 <%= form.input :publication_state, :as => :radio %>
9997ce6 @josevalim Added more information about inputs :for in README.
josevalim authored
27 <%= form.input :category %>
353618e @markmansour Extending Formtastic can be done by overriding the semantic_form_builder...
markmansour authored
28 <%= form.input :allow_comments, :label => "Allow commenting on this article" %>
29 <% end %>
30
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
31 <%= form.inputs :name => "Advanced" do %>
353618e @markmansour Extending Formtastic can be done by overriding the semantic_form_builder...
markmansour authored
32 <%= 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
33 <%= form.input :extract, :required => false %>
34 <%= form.input :description, :required => false %>
353618e @markmansour Extending Formtastic can be done by overriding the semantic_form_builder...
markmansour authored
35 <%= form.input :url_title, :required => false %>
7e3874a @justinfrench trying to fix README formatting of <'s at the start of lines
authored
36 <% end %>
37
90c6e29 @justinfrench Revert "use real objects in :for and fields_for examples"
authored
38 <%= form.inputs :name => "Author", :for => :author do |author_form| %>
05ae54d @josevalim Fixed nested attributes example in README
josevalim authored
39 <%= author_form.input :first_name %>
40 <%= author_form.input :last_name %>
9997ce6 @josevalim Added more information about inputs :for in README.
josevalim authored
41 <% end %>
42
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
43 <%= form.buttons do %>
353618e @markmansour Extending Formtastic can be done by overriding the semantic_form_builder...
markmansour authored
44 <%= form.commit_button %>
7e3874a @justinfrench trying to fix README formatting of <'s at the start of lines
authored
45 <% end %>
09d957d textilized the README so that it looks pretty pretty on GitHub
Justin French authored
46
dcf8beb Initial Commit
Justin French authored
47 <% end %>
09d957d textilized the README so that it looks pretty pretty on GitHub
Justin French authored
48 </pre>
49
6734cfd @justinfrench sme typos and cleanups in the readme
authored
50 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
51
52
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
53 h2. It's better than _SomeOtherFormBuilder_ because...
54
6688887 @grimen More README-polishing.
grimen authored
55 * 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.
56 * 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
57 * it's Rails 3 compatible (including nested forms).
f02b136 @justinfrench rearranged and beefed up the 'it's better than...' README section
authored
58 * it has internationalization (I18n)!
6688887 @grimen More README-polishing.
grimen authored
59 * 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.
60 * there's heaps of elements, id and class attributes for you to hook in your CSS and JS.
61 * it handles real world stuff like inline hints, inline error messages & help text.
62 * 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).
63 * it's got absolutely awesome spec coverage.
64 * there's a bunch of people using and working on it (it's not just one developer building half a solution).
13164f7 @justinfrench Allow HTML5 placeholder attributes to be set on String-ish inputs (strin...
authored
65 * it has growing HTML5 support (new inputs like email/phone/search, new attributes like required/min/max/step/placeholder)
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
66
67
15e0bd9 updated the README a little to match last night's slides
Justin French authored
68 h2. Why?
69
6688887 @grimen More README-polishing.
grimen authored
70 * web apps = lots of forms.
71 * forms are so friggin' boring to code.
72 * semantically rich & accessible forms really are possible.
73 * the "V" is way behind the "M" and "C" in Rails' MVC – it's the ugly sibling.
74 * best practices and common patterns have to start somewhere.
75 * i need a challenge.
dcf8beb Initial Commit
Justin French authored
76
77
15e0bd9 updated the README a little to match last night's slides
Justin French authored
78 h2. Opinions
79
6688887 @grimen More README-polishing.
grimen authored
80 * it should be easier to do things the right way than the wrong way.
81 * sometimes _more mark-up_ is better.
82 * elements and attribute hooks are _gold_ for stylesheet authors.
83 * 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
84
dcf8beb Initial Commit
Justin French authored
85
3dd6455 @justinfrench Link to RDoc URL in README
authored
86 h2. Documentation
87
88 RDoc documentation _should_ be automatically generated after each commit and made available on the "rdoc.info website":http://rdoc.info/projects/justinfrench/formtastic.
89
90
e3f04f6 @justinfrench README installation instructions simlified and clarified to specific tha...
authored
91 h2. Installation
c89e985 @justinfrench updating README with gem/plugin installation instructions
authored
92
ebe4e51 @justinfrench updated the README to reflect the new gem versions and other compatibili...
authored
93 Simply add Formtastic to your Gemfile and bundle it up:
557f929 @justinfrench updated README to reflect new 1.1.0.beta gem, etc
authored
94
95 <pre>
22a9af1 @justinfrench prep README for 2.0
authored
96 gem 'formtastic'
557f929 @justinfrench updated README to reflect new 1.1.0.beta gem, etc
authored
97 </pre>
98
22a9af1 @justinfrench prep README for 2.0
authored
99 Run the installation generator:
c89e985 @justinfrench updating README with gem/plugin installation instructions
authored
100
101 <pre>
e3f04f6 @justinfrench README installation instructions simlified and clarified to specific tha...
authored
102 $ rails generate formtastic:install
c89e985 @justinfrench updating README with gem/plugin installation instructions
authored
103 </pre>
104
ebe4e51 @justinfrench updated the README to reflect the new gem versions and other compatibili...
authored
105
106 h2. Stylesheets
c89e985 @justinfrench updating README with gem/plugin installation instructions
authored
107
28754a2 @justinfrench updated README for asset pipeline with ie6 & 7 css
authored
108 A proof-of-concept set of stylesheets are provided which you can include in your layout. Customization is best achieved by overriding these styles in an additional stylesheet.
4f4b069 @justinfrench Rails 3.1 Asset Pipeline compatibility (Fixes #563)
authored
109
110 h3. Stylesheet usage in Rails < 3.1:
111
112 <pre>
113 $ rails generate formtastic:install
114 </pre>
115
116 <pre>
117 # app/views/layouts/application.html.erb
118 <%= stylesheet_link_tag 'formtastic', 'my_formtastic_changes' %>
28754a2 @justinfrench updated README for asset pipeline with ie6 & 7 css
authored
119 <!--[if IE 6]><%= stylesheet_link_tag 'formtastic_ie6' %><![endif]-->
120 <!--[if IE 7]><%= stylesheet_link_tag 'formtastic_ie7' %><![endif]-->
4f4b069 @justinfrench Rails 3.1 Asset Pipeline compatibility (Fixes #563)
authored
121 </pre>
122
123 h3. Stylesheet usage in Rails >= 3.1:
124
28754a2 @justinfrench updated README for asset pipeline with ie6 & 7 css
authored
125 Rails 3.1 introduces an asset pipeline that allows plugins like Formtastic to serve their own Stylesheets, Javascripts, etc without having to run generators that copy them accross to the host application. Formtastic makes three stylesheets available as an Engine, you just need to require them in your global stylesheets.
c89e985 @justinfrench updating README with gem/plugin installation instructions
authored
126
5c1ce48 @justinfrench moved the stylesheets stuff up with installation
authored
127 <pre>
4f4b069 @justinfrench Rails 3.1 Asset Pipeline compatibility (Fixes #563)
authored
128 # app/assets/stylesheets/application.css
129 *= require formtastic
28754a2 @justinfrench updated README for asset pipeline with ie6 & 7 css
authored
130 *= require my_formtastic_changes
131
132 # app/assets/stylesheets/ie6.css
133 *= require formtastic_ie6
134
135 # app/assets/stylesheets/ie7.css
136 *= require formtastic_ie7
5c1ce48 @justinfrench moved the stylesheets stuff up with installation
authored
137 </pre>
2526d2c @justinfrench Going back to generators instead of Rake tasks for copying stylesheets a...
authored
138
28754a2 @justinfrench updated README for asset pipeline with ie6 & 7 css
authored
139 <pre>
140 # app/views/layouts/application.html.erb
141 <%= stylesheet_link_tag 'application' %>
142 <!--[if IE 6]><%= stylesheet_link_tag 'ie6' %><![endif]-->
143 <!--[if IE 7]><%= stylesheet_link_tag 'ie7' %><![endif]-->
144 </pre>
145
146
4036e74 @justinfrench pruning and cleaning up the README, it's been a while
authored
147
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
148 h2. Usage
149
150 Forms are really boring to code... you want to get onto the good stuff as fast as possible.
151
6688887 @grimen More README-polishing.
grimen authored
152 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
153
154 <pre>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
155 <%= semantic_form_for @user do |form| %>
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
156 <%= form.inputs %>
157 <%= form.buttons %>
158 <% end %>
159 </pre>
160
5018ed0 @justinfrench clarified the differences in Rails 2 and 3 ERB blocks, and some other st...
authored
161 This is a great way to get something up fast, but like scaffolding, it's not recommended for production.
162
163 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
164
165 <pre>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
166 <%= semantic_form_for @user do |form| %>
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
167 <%= form.inputs :title, :body, :section, :categories, :created_at %>
168 <%= form.buttons :commit %>
169 <% end %>
170 </pre>
171
5018ed0 @justinfrench clarified the differences in Rails 2 and 3 ERB blocks, and some other st...
authored
172 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
173
174 <pre>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
175 <%= semantic_form_for @post do |form| %>
176 <%= form.inputs do %>
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
177 <%= form.input :title %>
178 <%= form.input :body %>
179 <%= form.input :section, :as => :radio %>
180 <%= form.input :categories %>
181 <%= form.input :created_at, :as => :string %>
182 <% end %>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
183 <%= form.buttons do %>
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
184 <%= form.commit_button %>
185 <% end %>
186 <% end %>
187 </pre>
188
a45853c @justinfrench small README typo
authored
189 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
190
191 <pre>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
192 <%= semantic_form_for @post do |form| %>
193 <%= form.inputs "Basic", :id => "basic" do %>
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
194 <%= form.input :title %>
195 <%= form.input :body %>
196 <% end %>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
197 <%= form.inputs :name => "Advanced Options", :id => "advanced" do %>
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
198 <%= form.input :slug, :label => "URL Title", :hint => "Created automatically if left blank", :required => false %>
199 <%= form.input :section, :as => :radio %>
8d4d9ed @justinfrench Renamed (with backwards compatibility) and deprecation notices) :label_m...
authored
200 <%= form.input :user, :label => "Author", :member_label => :full_name %>
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
201 <%= form.input :categories, :required => false %>
202 <%= form.input :created_at, :as => :string, :label => "Publication Date", :required => false %>
203 <% end %>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
204 <%= form.buttons do %>
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
205 <%= form.commit_button %>
206 <% end %>
207 <% end %>
208 </pre>
209
4033f27 @nathanl Small addition to documentation
nathanl authored
210 You can create forms for nested resources:
211
212 <pre>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
213 <%= semantic_form_for [@author, @post] do |form| %>
4033f27 @nathanl Small addition to documentation
nathanl authored
214 </pre>
215
bcd3ba9 @justinfrench some README updates
authored
216 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
217
218 <pre>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
219 <%= semantic_form_for @post do |form| %>
05ae54d @josevalim Fixed nested attributes example in README
josevalim authored
220 <%= form.inputs :title, :body, :created_at %>
90c6e29 @justinfrench Revert "use real objects in :for and fields_for examples"
authored
221 <%= form.semantic_fields_for :author do |author| %>
1fcc068 @grimen An effort to make the README somewhat more readable.
grimen authored
222 <%= author.inputs :first_name, :last_name, :name => "Author" %>
41a6754 @josevalim Another README fix.
josevalim authored
223 <% end %>
05ae54d @josevalim Fixed nested attributes example in README
josevalim authored
224 <%= form.buttons %>
9997ce6 @josevalim Added more information about inputs :for in README.
josevalim authored
225 <% end %>
226 </pre>
227
6fd1bd2 @justinfrench improving the documentation in README
authored
228 Or the Formtastic way with the @:for@ option:
9997ce6 @josevalim Added more information about inputs :for in README.
josevalim authored
229
230 <pre>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
231 <%= semantic_form_for @post do |form| %>
05ae54d @josevalim Fixed nested attributes example in README
josevalim authored
232 <%= form.inputs :title, :body, :created_at %>
90c6e29 @justinfrench Revert "use real objects in :for and fields_for examples"
authored
233 <%= form.inputs :first_name, :last_name, :for => :author, :name => "Author" %>
05ae54d @josevalim Fixed nested attributes example in README
josevalim authored
234 <%= form.buttons %>
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
235 <% end %>
236 </pre>
237
1fcc068 @grimen An effort to make the README somewhat more readable.
grimen authored
238 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
239
240 <pre>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
241 <%= semantic_form_for @post do |form| %>
d5e3b0a @josevalim Added nested child nindex support.
josevalim authored
242 <%= form.inputs %>
90c6e29 @justinfrench Revert "use real objects in :for and fields_for examples"
authored
243 <%= form.inputs :name => 'Category #%i', :for => :categories %>
d5e3b0a @josevalim Added nested child nindex support.
josevalim authored
244 <%= form.buttons %>
245 <% end %>
246 </pre>
247
d174db0 @asanghi change id_prefix to namespace; added documentation in README
asanghi authored
248 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
249 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:
250
251 <pre>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
252 <%= semantic_form_for(@post, :namespace => 'cat_form') do |form| %>
253 <%= form.input :title %> # id="cat_form_post_title"
254 <%= form.input :body %> # id="cat_form_post_body"
255 <%= form.input :created_at %> # id="cat_form_post_created_at"
256 <%= form.buttons %>
d174db0 @asanghi change id_prefix to namespace; added documentation in README
asanghi authored
257 <% end %>
258 </pre>
6fd1bd2 @justinfrench improving the documentation in README
authored
259
29133e1 @dougireton Fixed minor typo in README Usage section.
dougireton authored
260 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
261
262 <pre>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
263 <%= semantic_form_for @post do |form| %>
a9889c5 @victorbstan defined :rows => 10, :cols => 20, :maxlength => 10 options in example to...
victorbstan authored
264 <%= form.input :title, :input_html => { :cols => 10 } %>
265 <%= form.input :body, :input_html => { :class => 'autogrow', :rows => 10, :cols => 20, :maxlength => 10 } %>
6fd1bd2 @justinfrench improving the documentation in README
authored
266 <%= form.input :created_at, :input_html => { :disabled => true } %>
267 <%= form.buttons %>
268 <% end %>
269 </pre>
270
271 The same can be done for buttons with the @:button_html@ option:
272
273 <pre>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
274 <%= semantic_form_for @post do |form| %>
6fd1bd2 @justinfrench improving the documentation in README
authored
275 ...
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
276 <%= form.buttons do %>
7e46509 @justinfrench documented :disable_with, fixes #466
authored
277 <%= form.commit_button :button_html => { :class => "primary", :disable_with => 'Wait...' } %>
6fd1bd2 @justinfrench improving the documentation in README
authored
278 <% end %>
279 <% end %>
280 </pre>
281
d174db0 @asanghi change id_prefix to namespace; added documentation in README
asanghi authored
282 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
283
6fd1bd2 @justinfrench improving the documentation in README
authored
284 <pre>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
285 <%= semantic_form_for @post do |form| %>
6fd1bd2 @justinfrench improving the documentation in README
authored
286 <%= form.input :title, :wrapper_html => { :class => "important" } %>
287 <%= form.input :body %>
288 <%= form.input :description, :wrapper_html => { :style => "display:none;" } %>
289 ...
290 <% end %>
291 </pre>
292
d174db0 @asanghi change id_prefix to namespace; added documentation in README
asanghi authored
293 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.
294
295 <pre>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
296 <%= semantic_form_for @post do |form| %>
d174db0 @asanghi change id_prefix to namespace; added documentation in README
asanghi authored
297 <%= form.input :title, :hint_class => 'custom-html-class', :error_class => 'custom-error-class' %>
298 <% end %>
299 </pre>
300
a92cf7c @justinfrench added documentation for :collection option, resolves #181
authored
301 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:
302
303 <pre>
304 f.input :authors, :as => :check_boxes, :collection => User.find(:all, :order => "last_name ASC")
305 f.input :authors, :as => :check_boxes, :collection => current_user.company.users.active
306 f.input :authors, :as => :check_boxes, :collection => [@justin, @kate]
307 f.input :authors, :as => :check_boxes, :collection => ["Justin", "Kate", "Amelia", "Gus", "Meg"]
308 f.input :author, :as => :select, :collection => Author.find(:all)
309 f.input :author, :as => :select, :collection => { @justin.name => @justin.id, @kate.name => @kate.id }
310 f.input :author, :as => :select, :collection => ["Justin", "Kate", "Amelia", "Gus", "Meg"]
311 f.input :author, :as => :radio, :collection => User.find(:all)
312 f.input :author, :as => :radio, :collection => [@justin, @kate]
313 f.input :author, :as => :radio, :collection => { @justin.name => @justin.id, @kate.name => @kate.id }
314 f.input :author, :as => :radio, :collection => ["Justin", "Kate", "Amelia", "Gus", "Meg"]
315 f.input :admin, :as => :radio, :collection => ["Yes!", "No"]
316 </pre>
317
6fd1bd2 @justinfrench improving the documentation in README
authored
318
5a39443 @justinfrench bulking up the documentation and readme with the different inputs availa...
authored
319 h2. The Available Inputs
320
d9a06fe @grimen README: Last set of polishing moves for now.
grimen authored
321 The Formtastic input types:
322
8577c18 @grimen More README-readability polishing.
grimen authored
323 * @:select@ - a select menu. Default for ActiveRecord associations: @belongs_to@, @has_many@, and @has_and_belongs_to_many@.
324 * @:check_boxes@ - a set of check_box inputs. Alternative to @:select@ for ActiveRecord-associations: @has_many@, and @has_and_belongs_to_many@.
325 * @:radio@ - a set of radio inputs. Alternative to @:select@ for ActiveRecord-associations: @belongs_to@.
326 * @:time_zone@ - a select input. Default for column types: @:string@ with name matching @"time_zone"@.
327 * @:password@ - a password input. Default for column types: @:string@ with name matching @"password"@.
328 * @:text@ - a textarea. Default for column types: @:text@.
329 * @:date@ - a date select. Default for column types: @:date@.
330 * @:datetime@ - a date and time select. Default for column types: @:datetime@ and @:timestamp@.
331 * @:time@ - a time select. Default for column types: @:time@.
332 * @:boolean@ - a checkbox. Default for column types: @:boolean@.
333 * @:string@ - a text field. Default for column types: @:string@.
a33f4d0 @justinfrench renamed NumericInput (:as => :numeric) to NumberInput (:as => :number)
authored
334 * @:number@ - a text field (just like string). Default for column types: @:integer@, @:float@, and @:decimal@.
8577c18 @grimen More README-readability polishing.
grimen authored
335 * @: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.
336 * @: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
337 * @:email@ - a text field (just like string). Default for columns with name matching @"email"@. New in HTML5. Works on some mobile browsers already.
338 * @:url@ - a text field (just like string). Default for columns with name matching @"url"@. New in HTML5. Works on some mobile browsers already.
339 * @:phone@ - a text field (just like string). Default for columns with name matching @"phone"@ or @"fax"@. New in HTML5.
340 * @: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
341 * @:hidden@ - a hidden field. Creates a hidden field (added for compatibility).
d877b6b @justinfrench Merge branch 'refactor' of https://github.com/okonski/formtastic into ok...
authored
342 * @:range@ - a slider field.
6688887 @grimen More README-polishing.
grimen authored
343
fd23ef4 @justinfrench tiny README tweak
authored
344 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.
345
5a39443 @justinfrench bulking up the documentation and readme with the different inputs availa...
authored
346
06ff25d @lardawge Added section clarifying label lookup order.
lardawge authored
347 h2. Delegation for label lookups
348
349 Formtastic decides which label to use in the following order:
350
351 <pre>
352 1. :label # :label => "Choose Title"
353 2. Formtastic i18n # if either :label => true || i18n_lookups_by_default = true (see Internationalization)
354 3. Activerecord i18n # if localization file found for the given attribute
355 4. label_str_method # if nothing provided this defaults to :humanize but can be set to a custom method
356 </pre>
357
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
358 h2. Internationalization (I18n)
359
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to re...
grimen authored
360 h3. Basic Localization
71ef99f @justinfrench nuked the configuration copy/paste from the README, linked to the genera...
authored
361
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to re...
grimen authored
362 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
363
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset ti...
grimen authored
364 Basic localization (labels only, with ActiveRecord):
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
365
366 <pre>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
367 <%= semantic_form_for @post do |form| %>
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
368 <%= form.input :title %> # => :label => I18n.t('activerecord.attributes.user.title') or 'Title'
369 <%= form.input :body %> # => :label => I18n.t('activerecord.attributes.user.body') or 'Body'
370 <%= form.input :section %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
371 <% end %>
372 </pre>
373
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to re...
grimen authored
374 *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?
375
376 h3. Enhanced Localization (Formtastic I18n API)
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
377
d9a06fe @grimen README: Last set of polishing moves for now.
grimen authored
378 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
379
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to re...
grimen authored
380 *1. Enable I18n lookups by default (@config/initializers/formtastic.rb@):*
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
381
382 <pre>
549ef7a @justinfrench Renamed all instances of Formtastic::SemanticFormBuilder to Formtastic::...
authored
383 Formtastic::FormBuilder.i18n_lookups_by_default = true
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
384 </pre>
385
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to re...
grimen authored
386 *2. Add some cool label-translations/variants (@config/locale/en.yml@):*
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
387
388 <pre>
389 en:
390 formtastic:
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset ti...
grimen authored
391 titles:
392 post_details: "Post details"
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
393 labels:
394 post:
13164f7 @justinfrench Allow HTML5 placeholder attributes to be set on String-ish inputs (strin...
authored
395 title: "Your Title"
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
396 body: "Write something..."
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset ti...
grimen authored
397 edit:
398 title: "Edit title"
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
399 hints:
400 post:
401 title: "Choose a good title for you post."
402 body: "Write something inspiring here."
13164f7 @justinfrench Allow HTML5 placeholder attributes to be set on String-ish inputs (strin...
authored
403 placeholders:
404 post:
405 title: "Title your post"
406 slug: "Leave blank for an automatically generated slug"
407 user:
408 email: "you@yours.com"
4aca8cd @grimen New I18n-features:
grimen authored
409 actions:
743b26b @yabawock Revert "Reverting two i18n patches pulled in from the rails3 branch whic...
yabawock authored
410 create: "Create my %{model}"
4aca8cd @grimen New I18n-features:
grimen authored
411 update: "Save changes"
412 dummie: "Launch!"
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
413 </pre>
414
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to re...
grimen authored
415 *3. ...and now you'll get:*
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
416
417 <pre>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
418 <%= semantic_form_for Post.new do |form| %>
419 <%= form.inputs do %>
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset ti...
grimen authored
420 <%= form.input :title %> # => :label => "Choose a title...", :hint => "Choose a good title for you post."
421 <%= form.input :body %> # => :label => "Write something...", :hint => "Write something inspiring here."
422 <%= form.input :section %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
423 <% end %>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
424 <%= form.buttons do %>
743b26b @yabawock Revert "Reverting two i18n patches pulled in from the rails3 branch whic...
yabawock authored
425 <%= form.commit_button %> # => "Create my %{model}"
4aca8cd @grimen New I18n-features:
grimen authored
426 <% end %>
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
427 <% end %>
428 </pre>
429
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to re...
grimen authored
430 *4. Localized titles (a.k.a. legends):*
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset ti...
grimen authored
431
17f6668 @justinfrench Revert "This reverts commit 440bd2d8da117acdbca57fa199c115caefcd87c0."
authored
432 _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
433
434 <pre>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
435 <%= semantic_form_for @post do |form| %>
436 <%= form.inputs :post_details do %> # => :title => "Post details"
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset ti...
grimen authored
437 # ...
438 <% end %>
439 # ...
440 <% end %>
441 </pre>
442
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to re...
grimen authored
443 *5. Override I18n settings:*
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
444
445 <pre>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
446 <%= semantic_form_for @post do |form| %>
447 <%= form.inputs do %>
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset ti...
grimen authored
448 <%= form.input :title %> # => :label => "Choose a title...", :hint => "Choose a good title for you post."
449 <%= form.input :body, :hint => false %> # => :label => "Write something..."
450 <%= form.input :section, :label => 'Some section' %> # => :label => 'Some section'
451 <% end %>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
452 <%= form.buttons do %>
4aca8cd @grimen New I18n-features:
grimen authored
453 <%= form.commit_button :dummie %> # => "Launch!"
454 <% end %>
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
455 <% end %>
456 </pre>
457
458 If I18n-lookups is disabled, i.e.:
459
460 <pre>
549ef7a @justinfrench Renamed all instances of Formtastic::SemanticFormBuilder to Formtastic::...
authored
461 Formtastic::FormBuilder.i18n_lookups_by_default = false
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
462 </pre>
463
464 ...then you can enable I18n within the forms instead:
465
466 <pre>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
467 <%= semantic_form_for @post do |form| %>
468 <%= form.inputs do %>
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset ti...
grimen authored
469 <%= form.input :title, :label => true %> # => :label => "Choose a title..."
470 <%= form.input :body, :label => true %> # => :label => "Write something..."
471 <%= form.input :section, :label => true %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
472 <% end %>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
473 <%= form.buttons do %>
4b1ba5f @dbackeus Updated expected commit_button text in README.
dbackeus authored
474 <%= form.commit_button true %> # => "Update %{model}" (if we are in edit that is...)
4aca8cd @grimen New I18n-features:
grimen authored
475 <% end %>
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
476 <% end %>
477 </pre>
478
49a18a5 @grimen README-update: I18n instructions are better structured, and easier to re...
grimen authored
479 *6. Advanced I18n lookups*
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
480
481 For more flexible forms; Formtastic find translations using a bottom-up approach taking the following variables in account:
482
75782e1 @grimen Updated I18n-instructions in README; on the I18n-support for fieldset ti...
grimen authored
483 * @MODEL@, e.g. "post"
484 * @ACTION@, e.g. "edit"
4aca8cd @grimen New I18n-features:
grimen authored
485 * @KEY/ATTRIBUTE@, e.g. "title", :my_custom_key, ...
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
486
487 ...in the following order:
488
6688887 @grimen More README-polishing.
grimen authored
489 1. @formtastic.{titles,labels,hints,actions}.MODEL.ACTION.ATTRIBUTE@ - by model and action
490 2. @formtastic.{titles,labels,hints,actions}.MODEL.ATTRIBUTE@ - by model
491 3. @formtastic.{titles,labels,hints,actions}.ATTRIBUTE@ - global default
94ce3ec @grimen Documentation for the new I18n features for labels/hints.
grimen authored
492
493 ...which means that you can define translations like this:
494
495 <pre>
496 en:
497 formtastic:
498 labels:
499 title: "Title" # Default global value
500 article:
501 body: "Article content"
502 post:
503 new:
504 title: "Choose a title..."
505 body: "Write something..."
506 edit:
507 title: "Edit title"
508 body: "Edit body"
509 </pre>
510
4aca8cd @grimen New I18n-features:
grimen authored
511 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
512
71ef99f @justinfrench nuked the configuration copy/paste from the README, linked to the genera...
authored
513
c4ebcef * added semantic_errors method with specs
Wojciech Wnętrzak authored
514 h2. Semantic errors
515
516 You can show errors on base (by default) and any other attribute just passing it name to semantic_errors method:
517
518 <pre>
bc5603b @justinfrench convert <% ... do %> to <%= ... do %> in README
authored
519 <%= semantic_form_for @post do |form| %>
c4ebcef * added semantic_errors method with specs
Wojciech Wnętrzak authored
520 <%= form.semantic_errors :state %>
521 <% end %>
522 </pre>
523
524
7687bf7 @justinfrench Added support for modified and custom inputs in app/inputs/.
authored
525 h2. Modified & Custom Inputs
ce7da5e @justinfrench added the builder config to the config template and quick documentation ...
authored
526
7687bf7 @justinfrench Added support for modified and custom inputs in app/inputs/.
authored
527 If you want to change the behaviour of an input, you can subclass it in your app. For example, to tweak @StringInput@, create a new file @app/inputs/string_input.rb@:
ce7da5e @justinfrench added the builder config to the config template and quick documentation ...
authored
528
7687bf7 @justinfrench Added support for modified and custom inputs in app/inputs/.
authored
529 <pre>
530 class StringInput < Formtastic::Inputs::StringInput
531 def to_html
532 puts "this is my modified version of StringInput"
533 super
534 end
535 end
536 </pre>
ce7da5e @justinfrench added the builder config to the config template and quick documentation ...
authored
537
7687bf7 @justinfrench Added support for modified and custom inputs in app/inputs/.
authored
538 To create your own new types of inputs based on existing inputs, the process is similar:
ce7da5e @justinfrench added the builder config to the config template and quick documentation ...
authored
539
28bb57f @paneq Resolves http://github.com/justinfrench/formtastic/issues/#issue/409
paneq authored
540 <pre>
7687bf7 @justinfrench Added support for modified and custom inputs in app/inputs/.
authored
541 # f.input(:body, :as => :flexible_text)
d57c054 @robinst README: Fix mention of inexistent StringTextInput
robinst authored
542 class FlexibleTextInput < Formtastic::Inputs::StringInput
7687bf7 @justinfrench Added support for modified and custom inputs in app/inputs/.
authored
543 def input_html_options
544 super.merge(:class => "flexible-text-area")
545 end
546 end
28bb57f @paneq Resolves http://github.com/justinfrench/formtastic/issues/#issue/409
paneq authored
547 </pre>
3f58f3a @justinfrench README update for --controller option form generator
authored
548
7687bf7 @justinfrench Added support for modified and custom inputs in app/inputs/.
authored
549 To create your own new types of inputs from scratch:
550
551 <pre>
552 # f.input(:created_at, :as => :date_picker)
34d6e16 @robinst README: Fix custom input example about DatePicker
robinst authored
553 class DatePickerInput
554 include Formtastic::Inputs::Base
555 def to_html
556 # ...
7687bf7 @justinfrench Added support for modified and custom inputs in app/inputs/.
authored
557 end
558 end
559 </pre>
560
22a9af1 @justinfrench prep README for 2.0
authored
561 It was previously recommended in Formtastic 1.x to subclass Formtastic::FormBuilder to add your own inputs. This is no longer recommended in Formtastic 2, and will not work as expected.
7687bf7 @justinfrench Added support for modified and custom inputs in app/inputs/.
authored
562
5f3d7a6 @justinfrench updated the generator docs in README to reflect both Rails 3 and 2
authored
563
2d2d813 @yabawock More intelligent way to html_escape labels and hints (GH-299)
yabawock authored
564 h2. Security
ce7da5e @justinfrench added the builder config to the config template and quick documentation ...
authored
565
22a9af1 @justinfrench prep README for 2.0
authored
566 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:
2d2d813 @yabawock More intelligent way to html_escape labels and hints (GH-299)
yabawock authored
567
549ef7a @justinfrench Renamed all instances of Formtastic::SemanticFormBuilder to Formtastic::...
authored
568 Formtastic::FormBuilder.escape_html_entities_in_hints_and_labels = false
3f58f3a @justinfrench README update for --controller option form generator
authored
569
570
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
571 h2. Dependencies
dcf8beb Initial Commit
Justin French authored
572
9af5cc8 @justinfrench Big update and re-organization of the README:
authored
573 There are none, but...
dcf8beb Initial Commit
Justin French authored
574
fe2fec0 @etehtsea typo fix
etehtsea authored
575 * if you want to use the @:country@ input, you'll need to install the "country-select plugin":https://github.com/chrislerum/country_select (or any other country_select plugin with the same API).
1fcc068 @grimen An effort to make the README somewhat more readable.
grimen authored
576 * "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
577
0b370ba @justinfrench Renamed input_field_set() to just inputs() and added a shorthand version...
authored
578
2079c59 @justinfrench added a section about contributing to README
authored
579 h2. How to contribute
580
533c086 @justinfrench added a section to the README on getting a dev environment up and runnin...
authored
581 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
582
583 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.
584
585 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.
586
533c086 @justinfrench added a section to the README on getting a dev environment up and runnin...
authored
587 See below for installation of a development environment.
588
589
90282e3 @justinfrench added twitter account to the readme
authored
590 h2. Google Group, Twitter, etc
5af0311 @justinfrench updated the README to pimp the google group more
authored
591
592 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.
593
90282e3 @justinfrench added twitter account to the readme
authored
594 You can also "follow @formtastic on Twitter":http://twitter.com/formtastic for announcements, tutorials and awesome Formtastic links.
595
ba3ce05 @justinfrench updated the README a little with contributors and some other busy work
authored
596 h2. Project Info
597
eff38a1 @justinfrench too hard to maintain the maintainers
authored
598 Formtastic was created by "Justin French":http://www.justinfrench.com with contributions from over 100 awesome developers.
599
600 Run @git shortlog -n -s@ to see the awesome.
ba3ce05 @justinfrench updated the README a little with contributors and some other busy work
authored
601
eff38a1 @justinfrench too hard to maintain the maintainers
authored
602 The project is hosted on Github: "http://github.com/justinfrench/formtastic":http://github.com/justinfrench/formtastic, where your contributions, forkings, comments, issues and feedback are greatly welcomed.
ba3ce05 @justinfrench updated the README a little with contributors and some other busy work
authored
603
ebe4e51 @justinfrench updated the README to reflect the new gem versions and other compatibili...
authored
604 Copyright (c) 2007-2010 Justin French, released under the MIT license.
Something went wrong with that request. Please try again.