@@ -8,25 +8,25 @@ Hacked together forms were easy, but awesome forms with decent semantics, rich m
8
8
9
9
<pre>
10
10
<% semantic_form_for @article do |form| %>
11
-
11
+
12
12
<% form.inputs :name => "Basic" do %>
13
- <%= form.input :title %>
14
- <%= form.input :body %>
15
- <%= form.input :section_id %>
16
- <%= form.input :publication_state_id, :as => :radio %>
17
- <%= form.input :author_id, :as => :select %>
18
- <%= form.input :allow_comments, :label => "Allow commenting on this article" %>
19
- <% end %>
20
-
13
+ <%= form.input :title %>
14
+ <%= form.input :body %>
15
+ <%= form.input :section_id %>
16
+ <%= form.input :publication_state_id, :as => :radio %>
17
+ <%= form.input :author_id, :as => :select %>
18
+ <%= form.input :allow_comments, :label => "Allow commenting on this article" %>
19
+ <% end %>
20
+
21
21
<% form.inputs :name => "Advanced" do %>
22
- <%= form.input :keywords, :required => false, :hint => "Example: ruby, rails, forms" %>
22
+ <%= form.input :keywords, :required => false, :hint => "Example: ruby, rails, forms" %>
23
23
<%= form.input :extract, :required => false %>
24
24
<%= form.input :description, :required => false %>
25
- <%= form.input :url_title, :required => false %>
25
+ <%= form.input :url_title, :required => false %>
26
26
<% end %>
27
27
28
- <% form.buttons do %>
29
- <%= form.commit_button %>
28
+ <% form.buttons do %>
29
+ <%= form.commit_button %>
30
30
<% end %>
31
31
32
32
<% end %>
@@ -191,6 +191,50 @@ You don't even have to specify the field list (Formtastic will simply render and
191
191
192
192
Pretty soon we won't have to write any code at all ;)
193
193
194
+ h2. Extending Formtastic
195
+
196
+ Adding functionality to Formtastic can be done by extending SemanticFormHelper.
197
+
198
+ <pre>
199
+ module JustinFrench #:nodoc:
200
+ module Formtastic #:nodoc:
201
+ class FancySemanticFormBuilder < SemanticFormBuilder
202
+
203
+ # new method to be added allowing full control over the label and value
204
+ def label_and_value(label_text, value, options = {})
205
+ options[:label] = label_text
206
+ content = text_label(label_text, options)
207
+ content += @template.content_tag(:span, value)
208
+ @template.content_tag(:li, content)
209
+ end
210
+ end
211
+ end
212
+ end
213
+ </pre>
214
+
215
+ To use this builder specify the builder name when defining the form.
216
+
217
+ <pre>
218
+ form_for(@post, :builder => JustinFrench::Formtastic::FancySemanticFormBuilder))
219
+ </pre>
220
+
221
+ The extended form builder can be placed in the RAILS_ROOT/lib directory and can be required in a Rails initializer.
222
+
223
+ If you want to make the extended form builder the default for the semantic_form_* methods then the SemanticFormBuilder can overridden to specify a new semantic_form_builder.
224
+
225
+ <pre>
226
+ module JustinFrench #:nodoc:
227
+ module Formtastic #:nodoc:
228
+ module TextEnabledSemanticFormHelper
229
+ def semantic_form_builder
230
+ JustinFrench::Formtastic::TextEnabledSemanticFormBuilder
231
+ end
232
+ end
233
+ end
234
+ end
235
+
236
+ ActionView::Base.send :include, JustinFrench::Formtastic::TextEnabledSemanticFormHelper
237
+ </pre>
194
238
195
239
h2. Conventions & Prerequisites
196
240
0 commit comments