bootstrap_form 2.1.1 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dedc77d50059c56a37534d9f6d75389a738af46f
4
- data.tar.gz: 9e1ee86b160a69cb40b1303f526106ba137b82b8
3
+ metadata.gz: 8742255adf9a08c30983097065574da44048f88e
4
+ data.tar.gz: 3b301bdd5e3c144a89151bb8b8f7eafb7a3a31e3
5
5
  SHA512:
6
- metadata.gz: ea9bc3f9d89c3bc5a2bd8275abe8deea23f867998557eb24105b57805a696559e03bdea89c410152b443a0713e0d16d7411b24ee102cca8c795bfaa935c7b22a
7
- data.tar.gz: 160591536c799d724da6d4f9afcb12ff0f1e89506084f77a6da702fd1f5ee615342b00bded0bfe83b82a6d77471c015b41ecbe29bf21218130db21ff9674a520
6
+ metadata.gz: 22c55ab50ba7ca0e6e7e9c5cd836d2461817d7a97036d87d13d52aa1cb62148d5e163fd1c68ca88806b76dd927cd30e1528dcbad8fbca8e502b9de1306875870
7
+ data.tar.gz: 2400158a438d1aed212116ccc6dc4c983b3ba0f8e5e02d0125e9971d747fafda44a38af10e2d6a9284eb4cb78bdab6d25330bccb62381c5e52820d1625a3f193
data/README.md CHANGED
@@ -22,9 +22,13 @@ Then:
22
22
 
23
23
  `bundle`
24
24
 
25
- Then require the CSS on your `application.css` file:
25
+ Then require the CSS in your `application.css` file:
26
26
 
27
- `//= require rails_bootstrap_forms`
27
+ ```css
28
+ /*
29
+ *= require rails_bootstrap_forms
30
+ */
31
+ ```
28
32
 
29
33
  ## Usage
30
34
 
@@ -35,7 +39,7 @@ To get started, just use the `bootstrap_form_for` helper. Here's an example:
35
39
  <%= f.email_field :email %>
36
40
  <%= f.password_field :password %>
37
41
  <%= f.check_box :remember_me %>
38
- <%= f.submit %>
42
+ <%= f.submit "Log In" %>
39
43
  <% end %>
40
44
  ```
41
45
 
@@ -64,7 +68,7 @@ This generates the following HTML:
64
68
  ### Nested Forms
65
69
 
66
70
  In order to active [nested_form](https://github.com/ryanb/nested_form) support,
67
- use `boostrap_nested_form_for` instead of `bootstrap_form_for`.
71
+ use `bootstrap_nested_form_for` instead of `bootstrap_form_for`.
68
72
 
69
73
  ### bootstrap_form_tag
70
74
 
@@ -72,17 +76,17 @@ If your form is not backed by a model, use the `bootstrap_form_tag`. Usage of th
72
76
 
73
77
  ```erb
74
78
  <%= bootstrap_form_tag url: '/subscribe' do |f| %>
75
- <%= f.email_field :email %>
79
+ <%= f.email_field :email, value: 'name@example.com' %>
76
80
  <%= f.submit %>
77
81
  <% end %>
78
82
  ```
79
83
 
80
- ### Supported Form Helpers
84
+ ## Form Helpers
81
85
 
82
86
  This gem wraps the following Rails form helpers:
83
87
 
84
88
  * check_box
85
- * check_boxes_collection
89
+ * collection_check_boxes
86
90
  * collection_select
87
91
  * color_field
88
92
  * date_field
@@ -99,7 +103,7 @@ This gem wraps the following Rails form helpers:
99
103
  * password_field
100
104
  * phone_field
101
105
  * radio_button
102
- * radio_buttons_collection
106
+ * collection_radio_buttons
103
107
  * range_field
104
108
  * search_field
105
109
  * select
@@ -108,121 +112,109 @@ This gem wraps the following Rails form helpers:
108
112
  * text_field
109
113
  * time_field
110
114
  * time_select
115
+ * time_zone_select
111
116
  * url_field
112
117
  * week_field
118
+
119
+ These helpers accept the same options as the standard Rails form helpers, with
120
+ a few extra options:
113
121
 
114
- ### Default Form Style
122
+ ### Labels
115
123
 
116
- By default, your forms will stack labels on top of controls and your controls
117
- will grow to 100% of the available width.
124
+ Use the `label` option if you want to specify the field's label text:
118
125
 
119
- ### Inline Forms
126
+ ```erb
127
+ <%= f.password_field :password_confirmation, label: "Confirm Password" %>
128
+ ```
120
129
 
121
- To use an inline-layout form, use the `layout: :inline` option. To hide labels,
122
- use the `hide_label: true` option, which keeps your labels accessible to those
123
- using screen readers.
130
+ To hide a label, use the `hide_label: true` option. This adds the `sr-only`
131
+ class, which keeps your labels accessible to those using screen readers.
124
132
 
125
133
  ```erb
126
- <%= bootstrap_form_for(@user, layout: :inline) do |f| %>
127
- <%= f.email_field :email, hide_label: true %>
128
- <%= f.password_field :password, hide_label: true %>
129
- <%= f.check_box :remember_me %>
130
- <%= f.submit %>
131
- <% end %>
134
+ <%= f.text_area :comment, hide_label: :true, placeholder: "Leave a comment..." %>
132
135
  ```
133
136
 
134
- ### Horizontal Forms
135
-
136
- To use a horizontal-layout form with labels to the left of the control, use the
137
- `layout: :horizontal` option. You should specify both `label_col` and
138
- `control_col` css classes as well (they default to `col-sm-2` and `col-sm-10`).
137
+ ### Help Text
139
138
 
140
- In the example below, the checkbox and submit button have been wrapped in a
141
- `form_group` to keep them properly aligned.
139
+ To add help text, use the `help` option:
142
140
 
143
141
  ```erb
144
- <%= bootstrap_form_for(@user, layout: :horizontal, label_col: "col-sm-2", control_col: "col-sm-10") do |f| %>
145
- <%= f.email_field :email %>
146
- <%= f.password_field :password %>
147
- <%= f.form_group do %>
148
- <%= f.check_box :remember_me %>
149
- <% end %>
150
- <%= f.form_group do %>
151
- <%= f.submit %>
152
- <% end %>
153
- <% end %>
142
+ <%= f.password_field :password, help: "Must be at least 6 characters long" %>
154
143
  ```
155
144
 
156
- The `label_col` and `control_col` css classes can also be changed per control:
145
+ This gem is also aware of help messages in locale translation files (i18n):
157
146
 
158
- ```erb
159
- <%= bootstrap_form_for(@user, layout: :horizontal) do |f| %>
160
- <%= f.email_field :email %>
161
- <%= f.text_field :age, control_col: "col-sm-3" %>
162
- <%= f.form_group do %>
163
- <%= f.submit %>
164
- <% end %>
165
- <% end %>
147
+ ```yml
148
+ en:
149
+ activerecord:
150
+ help:
151
+ user:
152
+ password: "A good password should be at least six characters long"
166
153
  ```
167
154
 
168
- ### Custom Field Layout
155
+ You can override help translations for a particular field by passing the `help`
156
+ option or turn them off completely by passing `help: false`.
169
157
 
170
- The `layout` can be overriden per field:
158
+ ### Icons
159
+
160
+ To add an icon to a field, use the `icon` option and pass the icon name
161
+ *without* the 'glyphicon' prefix:
171
162
 
172
163
  ```erb
173
- <%= bootstrap_form_for(@user, layout: :horizontal) do |f| %>
174
- <%= f.email_field :email %>
175
- <%= f.text_field :feet, layout: :inline %>
176
- <%= f.text_field :inches, layout: :inline %>
177
- <%= f.form_group do %>
178
- <%= f.submit %>
179
- <% end %>
180
- <% end %>
164
+ <%= f.text_field :login, icon: "user" %>
181
165
  ```
182
166
 
183
- ### Labels
184
-
185
- Use the `label` option if you want to specify the field's label text:
167
+ This automatically adds the `has-feedback` class to the `form-group`:
186
168
 
187
- ```erb
188
- <%= f.password_field :password_confirmation, label: "Confirm Password" %>
169
+ ```html
170
+ <div class="form-group has-feedback">
171
+ <label class="control-label" for="user_login">Login</label>
172
+ <input class="form-control" id="user_login" name="user[login]" type="text" />
173
+ <span class="glyphicon glyphicon-user form-control-feedback"></span>
174
+ </div>
189
175
  ```
190
176
 
191
- To hide a label, use the `hide_label: true` option. This adds the `sr-only`
192
- class, which keeps your labels accessible to those using screen readers.
177
+ ### Prepending and Appending Inputs
178
+
179
+ You can pass `prepend` and/or `append` options to input fields:
193
180
 
194
181
  ```erb
195
- <%= f.text_area :comment, hide_label: :true, placeholder: "Leave a comment..." %>
182
+ <%= f.text_field :price, prepend: "$", append: ".00" %>
196
183
  ```
197
184
 
198
- ### Help Text
199
-
200
- To add help text, use the `help` option:
185
+ You can also prepend and append buttons. Note: The buttons must contain the
186
+ `btn` class to generate the correct markup.
201
187
 
202
188
  ```erb
203
- <%= f.password_field :password, help: "Must be at least 6 characters long" %>
189
+ <%= f.text_field :search, append: link_to("Go", "#", class: "btn btn-default") %>
204
190
  ```
205
191
 
206
- ### Submit Buttons
192
+ ### Additional Form Group Attributes
207
193
 
208
- The `btn btn-default` css classes are automatically added to your submit
209
- buttons.
194
+ If you want to add an additional css class or any other attribute to the form group div, you can use
195
+ the `wrapper: { class: 'additional-class', data: { foo: 'bar' } }` option.
210
196
 
211
197
  ```erb
212
- <%= f.submit %>
198
+ <%= f.text_field :name, wrapper: { class: 'has-warning', data: { foo: 'bar' } } %>
213
199
  ```
214
200
 
215
- You can also use the `primary` helper, which adds `btn btn-primary` to your
216
- submit button **(master branch only)**:
201
+ Which produces the following output:
217
202
 
218
203
  ```erb
219
- <%= f.primary "Optional Label" %>
204
+ <div class="form-group has-warning" data-foo="bar">
205
+ <label class="control-label" for="user_name">Id</label>
206
+ <input class="form-control" id="user_name" name="user[name]" type="text">
207
+ </div>
220
208
  ```
221
209
 
222
- You can specify your own classes like this:
210
+ You still can use `wrapper_class` option to set only a css class. This is just a short form of `wrapper: { class: 'additional-class' }`.
211
+
212
+ ### Selects
213
+
214
+ Our select helper accepts the same arguments as the [default Rails helper](http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-select). Here's an example of how you pass both options and html_options hashes:
223
215
 
224
216
  ```erb
225
- <%= f.submit "Log In", class: "btn btn-success" %>
217
+ <%= f.select :product, [[1, "Apple"], [2, "Grape"]], { label: "Choose your favorite fruit:" }, { class: "selectpicker" } %>
226
218
  ```
227
219
 
228
220
  ### Checkboxes and Radios
@@ -265,29 +257,21 @@ To display checkboxes and radios inline, pass the `inline: true` option:
265
257
 
266
258
  #### Collections
267
259
 
268
- BootstrapForms also provide helpful helpers that automatically creates the
260
+ BootstrapForms also provideshelpers that automatically creates the
269
261
  `form_group` and the `radio_button`s or `check_box`es for you:
270
262
 
271
263
  ```erb
272
- <%= f.radio_buttons_collection :skill_level, Skill.all, :id, :name %>
273
- <%= f.check_boxes_collection :skills, Skill.all, :id, :name %>
264
+ <%= f.collection_radio_buttons :skill_level, Skill.all, :id, :name %>
265
+ <%= f.collection_check_boxes :skills, Skill.all, :id, :name %>
274
266
  ```
275
267
 
276
268
  Collection methods accept these options:
277
- * `:label`: Customize the `form_group`'s label;
278
- * `:hide_label`: Pass true to hide the `form_group`'s label;
279
- * `:help`: Add a help span to the `form_group`;
280
- * Other options will be forwarded to the `radio_button`/`check_box` method;
269
+ * `:label`: Customize the `form_group`'s label
270
+ * `:hide_label`: Pass true to hide the `form_group`'s label
271
+ * `:help`: Add a help span to the `form_group`
272
+ * Other options will be forwarded to the `radio_button`/`check_box` method
281
273
 
282
- ### Prepending and Appending Inputs
283
-
284
- You can pass `prepend` and/or `append` options to input fields:
285
-
286
- ```erb
287
- <%= f.text_field :price, prepend: "$", append: ".00" %>
288
- ```
289
-
290
- ### Static Controls **(master branch only)**
274
+ ### Static Controls
291
275
 
292
276
  You can create a static control like this:
293
277
 
@@ -309,12 +293,12 @@ Here's the output:
309
293
  You can also create a static control that isn't based on a model attribute:
310
294
 
311
295
  ```erb
312
- <%= f.static_control nil, label: "Custom Static Control" do %>
296
+ <%= f.static_control label: "Custom Static Control" do %>
313
297
  Content Here
314
298
  <% end %>
315
299
  ```
316
300
 
317
- ### Date helpers
301
+ ### Date Helpers
318
302
 
319
303
  The multiple selects that the date and time helpers (`date_select`,
320
304
  `time_select`, `datetime_select`) generate are wrapped inside a
@@ -322,60 +306,199 @@ The multiple selects that the date and time helpers (`date_select`,
322
306
  Boostrap automatically stylizes ours controls as `block`s. This wrapper fix
323
307
  this defining these selects as `inline-block` and a width of `auto`.
324
308
 
325
- ### Validation Errors
309
+ ### Submit Buttons
326
310
 
327
- When a validation error is triggered, the field will be outlined and the error
328
- will be displayed below the field. Rails normally wraps the fields in a div
329
- (field_with_errors), but this behavior is suppressed.
311
+ The `btn btn-default` css classes are automatically added to your submit
312
+ buttons.
330
313
 
331
- To display an error message wrapped in `.alert` and `.alert-danger`
332
- classes, you can use the `alert_message` helper. This won't output anything
333
- unless a model validation has failed.
314
+ ```erb
315
+ <%= f.submit %>
316
+ ```
317
+
318
+ You can also use the `primary` helper, which adds `btn btn-primary` to your
319
+ submit button **(master branch only)**:
334
320
 
335
321
  ```erb
336
- <%= f.alert_message "Please fix the errors below." %>
322
+ <%= f.primary "Optional Label" %>
337
323
  ```
338
324
 
339
- You can turn off inline errors with the option `inline_errors: false`. Combine
340
- this with `alert_message` to display an alert message with an error summary.
325
+ You can specify your own classes like this:
341
326
 
342
327
  ```erb
343
- <%= bootstrap_form_for(@user, inline_errors: false) do |f| %>
344
- <%= f.alert_message "Please fix the following errors:" %>
328
+ <%= f.submit "Log In", class: "btn btn-success" %>
329
+ ```
330
+
331
+ ### Accessing Rails Form Helpers
332
+
333
+ If you want to use the original Rails form helpers for a particular field,
334
+ append `_without_bootstrap` to the helper:
335
+
336
+ ```erb
337
+ <%= f.text_field_without_bootstrap :email %>
338
+ ```
339
+
340
+ ## Form Styles
341
+
342
+ By default, your forms will stack labels on top of controls and your controls
343
+ will grow to 100% of the available width.
344
+
345
+ ### Inline Forms
346
+
347
+ To use an inline-layout form, use the `layout: :inline` option. To hide labels,
348
+ use the `hide_label: true` option, which keeps your labels accessible to those
349
+ using screen readers.
350
+
351
+ ```erb
352
+ <%= bootstrap_form_for(@user, layout: :inline) do |f| %>
353
+ <%= f.email_field :email, hide_label: true %>
354
+ <%= f.password_field :password, hide_label: true %>
355
+ <%= f.check_box :remember_me %>
356
+ <%= f.submit %>
345
357
  <% end %>
346
358
  ```
347
359
 
348
- If you don't want an error summary, just send the `error_summary: false` option
349
- to `alert_message`.
360
+ ### Horizontal Forms
361
+
362
+ To use a horizontal-layout form with labels to the left of the control, use the
363
+ `layout: :horizontal` option. You should specify both `label_col` and
364
+ `control_col` css classes as well (they default to `col-sm-2` and `col-sm-10`).
365
+
366
+ In the example below, the checkbox and submit button have been wrapped in a
367
+ `form_group` to keep them properly aligned.
350
368
 
351
369
  ```erb
352
- <%= bootstrap_form_for(@user, inline_errors: false) do |f| %>
353
- <%= f.alert_message "Please fix the following errors", error_summary: false %>
370
+ <%= bootstrap_form_for(@user, layout: :horizontal, label_col: "col-sm-2", control_col: "col-sm-10") do |f| %>
371
+ <%= f.email_field :email %>
372
+ <%= f.password_field :password %>
373
+ <%= f.form_group do %>
374
+ <%= f.check_box :remember_me %>
375
+ <% end %>
376
+ <%= f.form_group do %>
377
+ <%= f.submit %>
378
+ <% end %>
354
379
  <% end %>
355
380
  ```
356
381
 
357
- To output a simple unordered list of errors, use `error_summary`.
382
+ The `label_col` and `control_col` css classes can also be changed per control:
383
+
384
+ ```erb
385
+ <%= bootstrap_form_for(@user, layout: :horizontal) do |f| %>
386
+ <%= f.email_field :email %>
387
+ <%= f.text_field :age, control_col: "col-sm-3" %>
388
+ <%= f.form_group do %>
389
+ <%= f.submit %>
390
+ <% end %>
391
+ <% end %>
392
+ ```
393
+
394
+ ### Custom Field Layout
395
+
396
+ The `layout` can be overriden per field:
397
+
398
+ ```erb
399
+ <%= bootstrap_form_for(@user, layout: :horizontal) do |f| %>
400
+ <%= f.email_field :email %>
401
+ <%= f.text_field :feet, layout: :default %>
402
+ <%= f.text_field :inches, layout: :default %>
403
+ <%= f.form_group do %>
404
+ <%= f.submit %>
405
+ <% end %>
406
+ <% end %>
407
+ ```
408
+
409
+ ## Validation & Errors
410
+
411
+ ### Inline Errors
412
+
413
+ By default, fields that have validation errors will outlined in red and the
414
+ error will be displayed below the field. Rails normally wraps the fields in a
415
+ div (field_with_errors), but this behavior is suppressed. Here's an example:
416
+
417
+ ```html
418
+ <div class="form-group has-error">
419
+ <label class="control-label" for="user_email">Email</label>
420
+ <input class="form-control" id="user_email" name="user[email]" type="email" value="">
421
+ <span class="help-block">can't be blank</span>
422
+ </div>
423
+ ```
424
+
425
+ You can turn off inline errors for the entire form like this:
358
426
 
359
427
  ```erb
360
428
  <%= bootstrap_form_for(@user, inline_errors: false) do |f| %>
361
- <%= f.error_summary %>
429
+ ...
362
430
  <% end %>
363
431
  ```
364
432
 
365
- If you want to display a custom inline error for a specific attribute not represented by a form field, use the `errors_on` helper.
433
+ ### Alert Messages
434
+
435
+ To display an error message with an error summary, you can use the
436
+ `alert_message` helper. This won't output anything unless a model validation
437
+ has failed.
438
+
439
+ ```erb
440
+ <%= f.alert_message "Please fix the errors below." %>
441
+ ```
442
+
443
+ Which outputs:
444
+
445
+ ```html
446
+ <div class="alert alert-danger">
447
+ <p>Please fix the errors below.</p>
448
+ <ul class="rails-bootstrap-forms-error-summary">
449
+ <li>Email can't be blank</li>
450
+ </ul>
451
+ </div>
452
+ ```
453
+
454
+ You can turn off the error summary like this:
455
+
456
+ ```erb
457
+ <%= f.alert_message "Please fix the errors below.", error_summary: false %>
458
+ ```
459
+
460
+ To output a simple unordered list of errors, use the `error_summary` helper.
461
+
462
+ ```erb
463
+ <%= f.error_summary %>
464
+ ```
465
+
466
+ Which outputs:
467
+
468
+ ```html
469
+ <ul class="rails-bootstrap-forms-error-summary">
470
+ <li>Email can't be blank</li>
471
+ </ul>
472
+ ```
473
+
474
+ ### Errors On
475
+
476
+ If you want to display a custom inline error for a specific attribute not
477
+ represented by a form field, use the `errors_on` helper.
366
478
 
367
479
  ```erb
368
480
  <%= f.errors_on :tasks %>
369
481
  ```
370
482
 
371
- The error will be wrapped in a div with `.alert` and `.alert-danger`
372
- classes.
483
+ Which outputs:
484
+
485
+ ```html
486
+ <div class="alert alert-danger">Tasks can't be blank.</div>
487
+ ```
488
+
489
+ You can hide the attribute name like this:
490
+
491
+ ```erb
492
+ <%= f.errors_on :tasks, hide_attribute_name: true %>
493
+ ```
494
+
495
+ Which outputs:
373
496
 
374
497
  ```html
375
- <div class="alert alert-danger">Tasks must be added (at least one).</div>
498
+ <div class="alert alert-danger">can't be blank.</div>
376
499
  ```
377
500
 
378
- ### Internationalization
501
+ ## Internationalization
379
502
 
380
503
  bootstrap_form follows standard rails conventions so it's i18n-ready. See more
381
504
  here: http://guides.rubyonrails.org/i18n.html#translations-for-active-record-models