justinfrench-formtastic 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +41 -27
- data/generators/formtastic_stylesheets/templates/formtastic.css +1 -0
- data/lib/formtastic.rb +1 -1
- data/spec/formtastic_spec.rb +20 -0
- metadata +2 -2
data/README.textile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
h1. Formtastic
|
1
|
+
h1. Formtastic
|
2
2
|
|
3
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
4
|
|
@@ -85,8 +85,7 @@ And then add it as a dependency in your environment.rb file:
|
|
85
85
|
<pre>
|
86
86
|
config.gem "justinfrench-formtastic",
|
87
87
|
:lib => 'formtastic',
|
88
|
-
:source => 'http://gems.github.com'
|
89
|
-
:version => '0.1.5'
|
88
|
+
:source => 'http://gems.github.com'
|
90
89
|
</pre>
|
91
90
|
|
92
91
|
If you're a little more old school, install it as a plugin:
|
@@ -100,7 +99,7 @@ h2. Usage
|
|
100
99
|
|
101
100
|
Forms are really boring to code... you want to get onto the good stuff as fast as possible.
|
102
101
|
|
103
|
-
This renders a set of inputs (one for _most_ columns in the database table, and one for each ActiveRecord belongs_to
|
102
|
+
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:
|
104
103
|
|
105
104
|
<pre>
|
106
105
|
<% semantic_form_for @user do |form| %>
|
@@ -135,7 +134,7 @@ If you want control over the input type Formtastic uses for each field, you can
|
|
135
134
|
<% end %>
|
136
135
|
</pre>
|
137
136
|
|
138
|
-
If you want to customize the label text, or render some hint text below the field, specify which fields are required/
|
137
|
+
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:
|
139
138
|
|
140
139
|
<pre>
|
141
140
|
<% semantic_form_for @post do |form| %>
|
@@ -156,48 +155,30 @@ If you want to customize the label text, or render some hint text below the fiel
|
|
156
155
|
<% end %>
|
157
156
|
</pre>
|
158
157
|
|
159
|
-
If you want to customize html elements for any non button inputs and the li
|
160
|
-
wrapper you just need to specify the :input_html and :wrapper_html options hash.
|
161
|
-
|
162
|
-
<pre>
|
163
|
-
<% semantic_form_for @post do |form| %>
|
164
|
-
<%= form.input :title, :input_html => {:size => 60} %>
|
165
|
-
<%= form.input :body, :wrapper_html => { :class => 'body_wrapper' } %>
|
166
|
-
<%= form.input :created_at, :input_html => {:disabled => true} %>
|
167
|
-
<%= form.buttons %>
|
168
|
-
<% end %>
|
169
|
-
</pre>
|
170
|
-
|
171
|
-
To customize buttons, :button_html is available.
|
172
158
|
|
173
159
|
Nested forms (Rails 2.3) are also supported. You can do it in the Rails way:
|
174
160
|
|
175
161
|
<pre>
|
176
162
|
<% semantic_form_for @post do |form| %>
|
177
163
|
<%= form.inputs :title, :body, :created_at %>
|
178
|
-
|
179
164
|
<% form.semantic_fields_for :author do |author| %>
|
180
165
|
<%= author.inputs :first_name, :last_name, :name => 'Author' %>
|
181
166
|
<% end %>
|
182
|
-
|
183
167
|
<%= form.buttons %>
|
184
168
|
<% end %>
|
185
169
|
</pre>
|
186
170
|
|
187
|
-
Or
|
171
|
+
Or the Formtastic way with the @:for@ option:
|
188
172
|
|
189
173
|
<pre>
|
190
174
|
<% semantic_form_for @post do |form| %>
|
191
175
|
<%= form.inputs :title, :body, :created_at %>
|
192
|
-
|
193
176
|
<%= form.inputs :first_name, :last_name, :for => :author, :name => "Author" %>
|
194
|
-
|
195
177
|
<%= form.buttons %>
|
196
178
|
<% end %>
|
197
179
|
</pre>
|
198
180
|
|
199
|
-
When working in has many association, you can even supply "%i" in your fieldset
|
200
|
-
name that it will be properly interpolated with the child index. For example:
|
181
|
+
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:
|
201
182
|
|
202
183
|
<pre>
|
203
184
|
<% semantic_form_for @post do |form| %>
|
@@ -207,8 +188,41 @@ name that it will be properly interpolated with the child index. For example:
|
|
207
188
|
<% end %>
|
208
189
|
</pre>
|
209
190
|
|
210
|
-
|
211
|
-
|
191
|
+
|
192
|
+
Customize HTML attributes for any input using the @:input_html@ option. Typically his is used to disable the input, change the size of a text field, change the rows in a textarea, or even to add a special class to an input to attach special behavior like "autogrow":http://plugins.jquery.com/project/autogrow textareas:
|
193
|
+
|
194
|
+
<pre>
|
195
|
+
<% semantic_form_for @post do |form| %>
|
196
|
+
<%= form.input :title, :input_html => { :size => 60 } %>
|
197
|
+
<%= form.input :body, :input_html => { :class => 'autogrow' } %>
|
198
|
+
<%= form.input :created_at, :input_html => { :disabled => true } %>
|
199
|
+
<%= form.buttons %>
|
200
|
+
<% end %>
|
201
|
+
</pre>
|
202
|
+
|
203
|
+
The same can be done for buttons with the @:button_html@ option:
|
204
|
+
|
205
|
+
<pre>
|
206
|
+
<% semantic_form_for @post do |form| %>
|
207
|
+
...
|
208
|
+
<% form.buttons do %>
|
209
|
+
<%= form.commit_button :button_html => { :class => "primary" } %>
|
210
|
+
<% end %>
|
211
|
+
<% end %>
|
212
|
+
</pre>
|
213
|
+
|
214
|
+
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")
|
215
|
+
|
216
|
+
<pre>
|
217
|
+
<% semantic_form_for @post do |form| %>
|
218
|
+
<%= form.input :title, :wrapper_html => { :class => "important" } %>
|
219
|
+
<%= form.input :body %>
|
220
|
+
<%= form.input :description, :wrapper_html => { :style => "display:none;" } %>
|
221
|
+
...
|
222
|
+
<% end %>
|
223
|
+
</pre>
|
224
|
+
|
225
|
+
|
212
226
|
|
213
227
|
h2. The Available Inputs
|
214
228
|
|
@@ -28,6 +28,7 @@ form.formtastic fieldset { }
|
|
28
28
|
form.formtastic fieldset.inputs { }
|
29
29
|
form.formtastic fieldset.buttons { padding-left:25%; }
|
30
30
|
form.formtastic fieldset ol { }
|
31
|
+
form.formtastic fieldset.buttons li { float:left; padding-right:0.5em; }
|
31
32
|
|
32
33
|
/* clearfixing the fieldsets */
|
33
34
|
form.formtastic fieldset { display: inline-block; }
|
data/lib/formtastic.rb
CHANGED
@@ -315,7 +315,7 @@ module Formtastic #:nodoc:
|
|
315
315
|
# :required can be also sent as option. When true, marks a filed as required,
|
316
316
|
# when false marks it as optional. When nil, does nothing.
|
317
317
|
#
|
318
|
-
def label(method, text, options={}, as_span=false)
|
318
|
+
def label(method, text=nil, options={}, as_span=false)
|
319
319
|
text ||= humanized_attribute_name(method)
|
320
320
|
text << required_or_optional_string(options.delete(:required))
|
321
321
|
|
data/spec/formtastic_spec.rb
CHANGED
@@ -286,6 +286,26 @@ describe 'Formtastic' do
|
|
286
286
|
end
|
287
287
|
end
|
288
288
|
|
289
|
+
describe '#label' do
|
290
|
+
it 'should humanize the given attribute' do
|
291
|
+
semantic_form_for(@new_post) do |builder|
|
292
|
+
builder.label(:login).should have_tag('label', :with => /Login/)
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
it 'should append required note' do
|
297
|
+
semantic_form_for(@new_post) do |builder|
|
298
|
+
builder.label(:login, nil, :required => true).should have_tag('label abbr')
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
it 'should be printed as span' do
|
303
|
+
semantic_form_for(@new_post) do |builder|
|
304
|
+
builder.label(:login, nil, { :required => true }, true).should have_tag('span.label abbr')
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
289
309
|
describe '#input' do
|
290
310
|
|
291
311
|
before do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: justinfrench-formtastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin French
|
@@ -9,7 +9,7 @@ autorequire: formtastic
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-22 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|