rails_bootstrap_form 0.8.0 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  # RailsBootstrapForm
2
2
 
3
- **rails_bootstrap_form** is a Rails form builder that makes it super easy to integrate
4
- [Bootstrap 5](https://getbootstrap.com/) forms into your Rails application.
3
+ [![Gem Version](https://badge.fury.io/rb/rails_bootstrap_form.svg)](https://badge.fury.io/rb/rails_bootstrap_form)
4
+
5
+ **rails_bootstrap_form** is a Rails form builder that makes it super easy to integrate [Bootstrap 5](https://getbootstrap.com/) forms into your Rails application.
6
+ `rails_bootstrap_forms`'s form helpers generate the form field and its label along with all the Bootstrap mark-up required for proper Bootstrap display.
5
7
 
6
8
  ## Minimum Requirements
7
9
 
@@ -11,18 +13,21 @@
11
13
 
12
14
  ## Installation
13
15
 
14
- Install Bootstrap 5. There are many ways to do this, depending on the asset pipeline you're using in your Rails application. One way is to use the gem that works with Sprockets. To do so, in a brand new Rails 7.0 application created _without_ the `--webpacker` option, add the `bootstrap` gem to your `Gemfile`:
16
+ Install Bootstrap 5. There are many ways to do this, depending on the asset pipeline you're using in your Rails application.
17
+ One way is to use the gem that works with Sprockets. To do so, in a brand new Rails 7.0 application created _without_ the
18
+ `--webpacker` option, add the `bootstrap` gem to your `Gemfile`:
15
19
 
16
20
  ```ruby
17
21
  gem "bootstrap", "~> 5.0"
18
22
  ```
19
23
 
20
- And follow the remaining instructions in the [official bootstrap installation guide](https://github.com/twbs/bootstrap-rubygem#a-ruby-on-rails) for setting up `application.scss` and `application.js`.
24
+ And follow the remaining instructions in the [official bootstrap installation guide](https://github.com/twbs/bootstrap-rubygem#a-ruby-on-rails)
25
+ for setting up `application.scss` and `application.js`.
21
26
 
22
27
  Add the `rails_bootstrap_form` gem to your `Gemfile`:
23
28
 
24
29
  ```ruby
25
- gem "rails_bootstrap_form", "~> 0.7.2"
30
+ gem "rails_bootstrap_form", "~> 0.8.2"
26
31
  ```
27
32
 
28
33
  Then:
@@ -36,7 +41,8 @@ If you use Rails in the default mode without any pre-processor, you'll have to a
36
41
  *= require rails_bootstrap_form
37
42
  ```
38
43
 
39
- If you followed the [official bootstrap installation guide](https://github.com/twbs/bootstrap-rubygem#a-ruby-on-rails), you'll probably have switched to SCSS. In this case add the following line to your `application.scss`:
44
+ If you followed the [official bootstrap installation guide](https://github.com/twbs/bootstrap-rubygem#a-ruby-on-rails),
45
+ you'll probably have switched to SCSS. In this case add the following line to your `application.scss`:
40
46
 
41
47
  ```scss
42
48
  @import "rails_bootstrap_form";
@@ -45,7 +51,7 @@ If you followed the [official bootstrap installation guide](https://github.com/t
45
51
  ## Configuration
46
52
 
47
53
  `rails_bootstrap_form` can be used without any configuration. However, `rails_bootstrap_form` does have an optional configuration file at `config/initializers/rails_bootstrap_form.rb` for setting options that affect all generated forms in an application. This configuration file is created using the generator
48
- by running the command on the terminal.
54
+ by running the command:
49
55
 
50
56
  ```
51
57
  $ rails generate rails_bootstrap_form:install
@@ -71,7 +77,7 @@ The current configuration options are:
71
77
 
72
78
  ### bootstrap_form_for
73
79
 
74
- To get started, use the `bootstrap_form_for` helper in place of the Rails `form_for` helper. Here's an example:
80
+ To get started, use the `bootstrap_form_for` helper in place of the Rails [`form_for`](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_for) helper. Here's an example:
75
81
 
76
82
  ![bootstrap_form_for](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/dfc5f03b-049a-4c12-b575-8298cf5551d7)
77
83
 
@@ -86,7 +92,6 @@ To get started, use the `bootstrap_form_for` helper in place of the Rails `form_
86
92
 
87
93
  This generates the following HTML:
88
94
 
89
-
90
95
  ```html
91
96
  <form role="form" novalidate="novalidate" class="new_user" id="new_user" action="/users" accept-charset="UTF-8" method="post">
92
97
  <div class="mb-3">
@@ -108,7 +113,7 @@ This generates the following HTML:
108
113
 
109
114
  ### bootstrap_form_with
110
115
 
111
- To get started, use the `bootstrap_form_with` helper in place of the Rails `form_with` helper. Here's an example:
116
+ To get started, use the `bootstrap_form_with` helper in place of the Rails [`form_with`](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_with) helper. Here's an example:
112
117
 
113
118
  ![bootstrap_form_with](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/06c605b9-29e2-4670-9495-0e913508d73f)
114
119
 
@@ -123,7 +128,6 @@ To get started, use the `bootstrap_form_with` helper in place of the Rails `form
123
128
 
124
129
  This generates the following HTML:
125
130
 
126
-
127
131
  ```html
128
132
  <form role="form" novalidate="novalidate" class="new_user" id="new_user" action="/users" accept-charset="UTF-8" method="post">
129
133
  <div class="mb-3">
@@ -143,7 +147,7 @@ This generates the following HTML:
143
147
  </form>
144
148
  ```
145
149
 
146
- ## Bootstrap configuration options
150
+ ## Bootstrap Configuration Options
147
151
 
148
152
  Here's a list of all possible options you can pass via `bootstrap_form` option that can be attached to the `bootstrap_form_for` or `bootstrap_form_with` or any field helpers inside of it:
149
153
 
@@ -216,7 +220,7 @@ This generates the following HTML:
216
220
  </form>
217
221
  ```
218
222
 
219
- ## Supported form helpers
223
+ ## Supported Form Helpers
220
224
 
221
225
  This gem wraps most of the form field helpers. Here's the current list:
222
226
 
@@ -228,15 +232,15 @@ datetime_select email_field file_field
228
232
  grouped_collection_select hidden_field month_field
229
233
  number_field password_field phone_field
230
234
  radio_button range_field rich_text_area
231
- search_field select static_field
232
- telephone_field text_area text_field
233
- time_field time_select time_zone_select
235
+ search_field select static_field
236
+ telephone_field text_area text_field
237
+ time_field time_select time_zone_select
234
238
  url_field week_field weekday_select
235
239
  ```
236
240
 
237
241
  ## Supported form layouts
238
242
 
239
- ### Vertical layout
243
+ ### Vertical Layout
240
244
 
241
245
  This layout is default layout for the form in which labels are above the fields and labels and fields take 100% of the width.
242
246
 
@@ -268,11 +272,11 @@ This generates the following HTML:
268
272
  </form>
269
273
  ```
270
274
 
271
- ### Horizontal layout
275
+ ### Horizontal Layout
272
276
 
273
277
  If you want to align label and field side by side, you can use horizontal layout for the form.
274
- You can optionally override `label_col_wrapper_class` and `field_col_wrapper_class` at either form level or field helpers if want to customize
275
- space between label and field.
278
+ You can optionally override `label_col_wrapper_class` and `field_col_wrapper_class` (they default to `col-sm-2` and `col-sm-10`) at either form level
279
+ or field helpers if want to customize space between label and field.
276
280
 
277
281
  Here's an example of how it looks like by default:
278
282
 
@@ -305,7 +309,62 @@ This generates the following HTML:
305
309
  </form>
306
310
  ```
307
311
 
308
- ### Inline layout
312
+ The `label_col_wrapper_class` and `field_col_wrapper_class` css classes can also be changed per control:
313
+
314
+ ![horizontal_form_custom_classes](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/ae5492f0-4a10-4f63-ae4d-9675bfb93226)
315
+
316
+ ```erb
317
+ <%= bootstrap_form_for @user, bootstrap_form: {layout: :horizontal} do |form| %>
318
+ <%= form.text_field :name %>
319
+ <%= form.email_field :username, bootstrap_form: {label_col_wrapper_class: "col-sm-2", field_col_wrapper_class: "col-sm-6"} %>
320
+ <%= form.password_field :password %>
321
+ <%= form.fields_for :address, include_id: false do |address_form| %>
322
+ <%= address_form.select :country_id, options_for_select(::Country.pluck(:name, :id), address_form.object.country_id),
323
+ {include_blank: "Select Country"} %>
324
+ <% end %>
325
+ <%= form.primary "Register" %>
326
+ <% end %>
327
+ ```
328
+
329
+ This generates the following HTML:
330
+
331
+ ```html
332
+ <form role="form" novalidate="novalidate" class="new_user" id="new_user" action="/users" accept-charset="UTF-8" method="post">
333
+ <div class="row mb-3">
334
+ <label class="col-form-label col-sm-2 required" for="user_name">Name</label>
335
+ <div class="col-sm-10">
336
+ <input class="form-control" aria-required="true" required="required" type="text" name="user[name]" id="user_name">
337
+ </div>
338
+ </div>
339
+ <div class="row mb-3">
340
+ <label class="col-form-label col-sm-2" for="user_username">Username</label>
341
+ <div class="col-sm-6">
342
+ <input class="form-control" type="email" name="user[username]" id="user_username">
343
+ </div>
344
+ </div>
345
+ <div class="row mb-3">
346
+ <label class="col-form-label col-sm-2 required" for="user_password">Password</label>
347
+ <div class="col-sm-10">
348
+ <input class="form-control" aria-required="true" required="required" type="password" name="user[password]" id="user_password">
349
+ </div>
350
+ </div>
351
+ <div class="row mb-3">
352
+ <label class="col-form-label col-sm-2 required" for="user_address_attributes_country_id">Country</label>
353
+ <div class="col-sm-10">
354
+ <select class="form-select" aria-required="true" required="required" name="user[address_attributes][country_id]" id="user_address_attributes_country_id">
355
+ <option value="">Select Country</option>
356
+ <option value="1">India</option>
357
+ <option value="2">Ireland</option>
358
+ <option value="3">United States</option>
359
+ <option value="4">United Kingdom</option>
360
+ </select>
361
+ </div>
362
+ </div>
363
+ <input type="submit" name="commit" value="Register" class="btn btn-primary" data-disable-with="Register">
364
+ </form>
365
+ ```
366
+
367
+ ### Inline Layout
309
368
 
310
369
  You may choose to render form elements in one line. Please note that this layout won't render all form elements perfectly. Things like errors messages and help text won't show up right.
311
370
 
@@ -338,3 +397,1412 @@ This generates the following HTML:
338
397
  </div>
339
398
  </form>
340
399
  ```
400
+
401
+ ## Components
402
+
403
+ `rails_bootstrap_form` internally supports below components which act as helpers to build fields and their wrappers.
404
+
405
+ ### Labels
406
+
407
+ By default, Rails takes label text from locale file. You can use `label_text` option to change label text
408
+ generated by the Rails.
409
+
410
+ ![label_text](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/b6378a06-c8e0-4944-8e0c-940a25964062)
411
+
412
+ ```erb
413
+ <%= form.password_field :password, bootstrap_form: {label_text: "New password"} %>
414
+ ```
415
+
416
+ This generates the following HTML:
417
+
418
+ ```html
419
+ <div class="mb-3">
420
+ <label class="form-label required" for="user_password">New password</label>
421
+ <input class="form-control" aria-required="true" required="required" type="password" name="user[password]" id="user_password">
422
+ </div>
423
+ ```
424
+
425
+ To hide a label, you can set `hide_label` option to `true`. This adds the `visually-hidden` class, which keeps your labels accessible
426
+ to those using screen readers.
427
+
428
+ ![hide_label](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/512a16b9-6829-40a2-bf07-f087970c9dac)
429
+
430
+ ```erb
431
+ <%= form.password_field :password, bootstrap_form: {hide_label: true} %>
432
+ ```
433
+
434
+ This generates the following HTML:
435
+
436
+ ```html
437
+ <div class="mb-3">
438
+ <label class="form-label visually-hidden required" for="user_password">Password</label>
439
+ <input class="form-control" aria-required="true" required="required" type="password" name="user[password]" id="user_password">
440
+ </div>
441
+ ```
442
+
443
+ To skip a label, you can set `skip_label` option to `true`. This will not render label in a field wrapper.
444
+
445
+ ![skip_label](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/251e28ac-b98b-4e6a-8d55-8c0cb061e65a)
446
+
447
+ ```erb
448
+ <%= form.password_field :password, bootstrap_form: {skip_label: true} %>
449
+ ```
450
+
451
+ This generates the following HTML:
452
+
453
+ ```html
454
+ <div class="mb-3">
455
+ <input class="form-control" aria-required="true" required="required" type="password" name="user[password]" id="user_password">
456
+ </div>
457
+ ```
458
+
459
+ To add additional CSS class to the label, you can use `additional_label_class` option.
460
+
461
+ ![additional_label_class](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/b5ab4efe-2512-4ee4-9d35-99d3b7f78171)
462
+
463
+ ```erb
464
+ <%= form.password_field :password, bootstrap_form: {additional_label_class: "text-danger"} %>
465
+ ```
466
+
467
+ This generates the following HTML:
468
+
469
+ ```html
470
+ <div class="mb-3">
471
+ <label class="form-label text-danger required" for="user_password">Password</label>
472
+ <input class="form-control" aria-required="true" required="required" type="password" name="user[password]" id="user_password">
473
+ </div>
474
+ ```
475
+
476
+ ### Help Text
477
+
478
+ The help text is useful when you want to provide helpful information about a field. By default, `rails_bootstrap_form` takes help text from locale file.
479
+ If you want to show information regarding any field, you need to add it in locale file of your application. You can also use HTML content for help text.
480
+
481
+ ```yml
482
+ en:
483
+ activerecord:
484
+ help_texts:
485
+ user:
486
+ password: "A strong password should be at least twelve characters long with combination of uppercase letters, lowercase letters, numbers, and symbols"
487
+ ```
488
+
489
+ ![help_text_from_translation](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/e6d94d8c-9b47-4940-b2e0-6f1efef5a720)
490
+
491
+ ```erb
492
+ <%= form.password_field :password %>
493
+ ```
494
+
495
+ This generates the following HTML:
496
+
497
+ ```html
498
+ <div class="mb-3">
499
+ <label class="form-label required" for="user_password">Password</label>
500
+ <input class="form-control" aria-required="true" required="required" type="password" name="user[password]" id="user_password">
501
+ <div class="form-text text-muted">A strong password should be at least twelve characters long with combination of uppercase letters, lowercase letters, numbers, and symbols</div>
502
+ </div>
503
+ ```
504
+
505
+ You can customize the help text using `help_text` option:
506
+
507
+ ![help_text](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/cdfe0e3c-6fcd-45a4-9621-9f0341925a1c)
508
+
509
+ ```erb
510
+ <%= form.password_field :password, bootstrap_form: {help_text: "Password should not be disclosed to anyone."} %>
511
+ ```
512
+
513
+ This generates the following HTML:
514
+
515
+ ```html
516
+ <div class="mb-3">
517
+ <label class="form-label required" for="user_password">Password</label>
518
+ <input class="form-control" aria-required="true" required="required" type="password" name="user[password]" id="user_password">
519
+ <div class="form-text text-muted">Password should not be disclosed to anyone.</div>
520
+ </div>
521
+ ```
522
+
523
+ You can also disable help text by setting `help_text` option to `false`:
524
+
525
+ ![help_text_false](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/be1a229a-cffd-447d-b846-9b9588b1b25e)
526
+
527
+ ```erb
528
+ <%= form.password_field :password, help_text: false %>
529
+ ```
530
+
531
+ This generates the following HTML:
532
+
533
+ ```html
534
+ <div class="mb-3">
535
+ <label class="form-label required" for="user_password">Password</label>
536
+ <input class="form-control" aria-required="true" required="required" type="password" name="user[password]" id="user_password">
537
+ </div>
538
+ ```
539
+
540
+ ### Input Groups
541
+
542
+ Input groups allow prepending and appending arbitrary html or text to the field.
543
+
544
+ You can use `prepend` and/or `append` options to attach addons to input fields:
545
+
546
+ ![input_group_addon](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/e7fb8f52-558d-458d-a112-2ee3bab366db)
547
+
548
+ ```erb
549
+ <%= form.number_field :expected_ctc, bootstrap_form: {prepend: "₹", append: ".00"} %>
550
+ ```
551
+
552
+ This generates the following HTML:
553
+
554
+ ```html
555
+ <div class="mb-3">
556
+ <label class="form-label" for="user_expected_ctc">Expected CTC</label>
557
+ <div class="input-group">
558
+ <span class="input-group-text">₹</span>
559
+ <input class="form-control" type="number" name="user[expected_ctc]" id="user_expected_ctc">
560
+ <span class="input-group-text">.00</span>
561
+ </div>
562
+ </div>
563
+ ```
564
+
565
+ If you want to attach multiple addons to the input, pass them as an array:
566
+
567
+ ![input_group_multiple_addons](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/8a6179c2-0def-428a-8429-c97db2c4a567)
568
+
569
+ ```erb
570
+ <%= form.number_field :expected_ctc, bootstrap_form: {prepend: ["Gross", "₹"], append: [".00", "per annum"]} %>
571
+ ```
572
+
573
+ This generates the following HTML:
574
+
575
+ ```html
576
+ <div class="mb-3">
577
+ <label class="form-label" for="user_expected_ctc">Expected CTC</label>
578
+ <div class="input-group">
579
+ <span class="input-group-text">Gross</span>
580
+ <span class="input-group-text">₹</span>
581
+ <input class="form-control" type="number" name="user[expected_ctc]" id="user_expected_ctc">
582
+ <span class="input-group-text">.00</span>
583
+ <span class="input-group-text">per annum</span>
584
+ </div>
585
+ </div>
586
+ ```
587
+
588
+ You can also prepend and append buttons. Note that these buttons must contain the `btn` class to generate the correct markup.
589
+
590
+ ![input_group_button](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/f0d1e22a-ca2b-42da-b99c-f3e7003d8c27)
591
+
592
+ ```erb
593
+ <%= form.text_field :search, bootstrap_form: {append: form.secondary("Search")} %>
594
+ ```
595
+
596
+ This generates the following HTML:
597
+
598
+ ```html
599
+ <div class="mb-3">
600
+ <label class="form-label" for="user_search">Search</label>
601
+ <div class="input-group">
602
+ <input class="form-control" type="text" name="user[search]" id="user_search">
603
+ <input type="submit" name="commit" value="Search" class="btn btn-secondary" data-disable-with="Search">
604
+ </div>
605
+ </div>
606
+ ```
607
+
608
+ To add additional CSS class to the input group wrapper, you can use `additional_input_group_class` option.
609
+
610
+ ![additional_input_group_class](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/1814ec85-1efe-4ffc-ba87-c171d1b73e2c)
611
+
612
+ ```erb
613
+ <%= form.number_field :expected_ctc, bootstrap_form: {prepend: "₹", append: ".00", additional_input_group_class: "custom-class"} %>
614
+ ```
615
+
616
+ This generates the following HTML:
617
+
618
+ ```html
619
+ <div class="mb-3">
620
+ <label class="form-label" for="user_expected_ctc">Expected CTC</label>
621
+ <div class="input-group custom-class">
622
+ <span class="input-group-text">₹</span>
623
+ <input class="form-control" type="number" name="user[expected_ctc]" id="user_expected_ctc">
624
+ <span class="input-group-text">.00</span>
625
+ </div>
626
+ </div>
627
+ ```
628
+
629
+ You can customize size of the input group using `size` option. Input group supports `sm` and `lg` values.
630
+
631
+ ![input_group_size](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/b7236bd6-4dad-4142-b14e-f6325a612958)
632
+
633
+ ```erb
634
+ <%= form.number_field :expected_ctc, bootstrap_form: {prepend: "₹", append: ".00", size: :sm} %>
635
+ ```
636
+
637
+ This generates the following HTML:
638
+
639
+ ```html
640
+ <div class="mb-3">
641
+ <label class="form-label" for="user_expected_ctc">Expected CTC</label>
642
+ <div class="input-group input-group-sm">
643
+ <span class="input-group-text">₹</span>
644
+ <input class="form-control form-control-sm" type="number" name="user[expected_ctc]" id="user_expected_ctc">
645
+ <span class="input-group-text">.00</span>
646
+ </div>
647
+ </div>
648
+ ```
649
+
650
+ ## Form Helpers
651
+
652
+ Our form helpers accept the same arguments as the default Rails form helpers.
653
+ In order to apply addition options of `rails_bootstrap_form`, `bootstrap_form` object is passed in `options` argument of the helper.
654
+ Here's an example of how you pass the arguments for each form helper:
655
+
656
+ ### check_box
657
+
658
+ Our `check_box` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-check_box).
659
+ This helper will render check box and label for you.
660
+
661
+ ![check_box](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/5836650c-d536-4f4e-b768-75bca9dd7901)
662
+
663
+ ```erb
664
+ <%= form.check_box :remember_me %>
665
+ ```
666
+
667
+ This generates the following HTML:
668
+
669
+ ```html
670
+ <div class="form-check mb-3">
671
+ <input name="user[remember_me]" type="hidden" value="0" autocomplete="off">
672
+ <input class="form-check-input" type="checkbox" value="1" name="user[remember_me]" id="user_remember_me">
673
+ <label class="form-check-label" for="user_remember_me">Keep me signed in</label>
674
+ </div>
675
+ ```
676
+
677
+ You can set `switch` option to `true` if you want check box to look like switches.
678
+
679
+ ![check_box_switch](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/20c493ce-7f2c-4ac9-a854-e1520cae6a54)
680
+
681
+ ```erb
682
+ <%= form.check_box :remember_me, bootstrap_form: {switch: true} %>
683
+ ```
684
+
685
+ This generates the following HTML:
686
+
687
+ ```html
688
+ <div class="form-check form-switch mb-3">
689
+ <input name="user[remember_me]" type="hidden" value="0" autocomplete="off">
690
+ <input class="form-check-input" type="checkbox" value="1" name="user[remember_me]" id="user_remember_me">
691
+ <label class="form-check-label" for="user_remember_me">Keep me signed in</label>
692
+ </div>
693
+ ```
694
+
695
+ This helper also renders help text if `help_text` option is set or information of the field is added to the locale file:
696
+
697
+ ![check_box_help_text](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/071a6ac3-112c-42d0-965f-cd7751fdff19)
698
+
699
+ ```erb
700
+ <%= form.check_box :terms, required: true %>
701
+ ```
702
+
703
+ This generates the following HTML:
704
+
705
+ ```html
706
+ <div class="form-check mb-3">
707
+ <input name="user[terms]" type="hidden" value="0" autocomplete="off">
708
+ <input required="required" class="form-check-input" type="checkbox" value="1" name="user[terms]" id="user_terms">
709
+ <label class="form-check-label required" for="user_terms">I accept terms and conditions</label>
710
+ <div class="form-text text-muted">You must first accept terms and conditions in order to continue</div>
711
+ </div>
712
+ ```
713
+
714
+ ### color_field
715
+
716
+ Our `color_field` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-color_field).
717
+
718
+ ![color_field](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/d83f8231-076f-48cc-b27c-4076d6be8ab6)
719
+
720
+ ```erb
721
+ <%= form.color_field :favorite_color %>
722
+ ```
723
+
724
+ This generates the following HTML:
725
+
726
+ ```html
727
+ <div class="mb-3">
728
+ <label class="form-label required" for="user_favorite_color">Favorite color</label>
729
+ <input class="form-control form-control-color" aria-required="true" required="required" value="#000000" type="color" name="user[favorite_color]" id="user_favorite_color">
730
+ </div>
731
+ ```
732
+
733
+ ### date_field
734
+
735
+ Our `date_field` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-date_field).
736
+
737
+ ![date_field](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/ddab2730-4076-4d0d-91c8-08b1f231741b)
738
+
739
+ ```erb
740
+ <%= form.date_field :interview_date %>
741
+ ```
742
+
743
+ This generates the following HTML:
744
+
745
+ ```html
746
+ <div class="mb-3">
747
+ <label class="form-label" for="user_interview_date">Interview date</label>
748
+ <input class="form-control" value="2023-05-08" type="date" name="user[interview_date]" id="user_interview_date">
749
+ </div>
750
+ ```
751
+
752
+ ### datetime_field
753
+
754
+ Our `datetime_field` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-datetime_field).
755
+
756
+ ![datetime_field](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/3b311f50-927f-4aa6-974a-2f5d0d79ff4f)
757
+
758
+ ```erb
759
+ <%= form.datetime_field :interview_datetime %>
760
+ ```
761
+
762
+ This generates the following HTML:
763
+
764
+ ```html
765
+ <div class="mb-3">
766
+ <label class="form-label" for="user_interview_datetime">Interview date &amp; time</label>
767
+ <input class="form-control" type="datetime-local" name="user[interview_datetime]" id="user_interview_datetime">
768
+ </div>
769
+ ```
770
+
771
+ ### datetime_local_field
772
+
773
+ Our `datetime_local_field` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-datetime_local_field).
774
+
775
+ ![datetime_local_field](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/ec9241a4-aa6e-448f-8478-04dba1cb7c11)
776
+
777
+ ```erb
778
+ <%= form.datetime_local_field :interview_datetime %>
779
+ ```
780
+
781
+ This generates the following HTML:
782
+
783
+ ```html
784
+ <div class="mb-3">
785
+ <label class="form-label" for="user_interview_datetime">Interview date &amp; time</label>
786
+ <input class="form-control" type="datetime-local" name="user[interview_datetime]" id="user_interview_datetime">
787
+ </div>
788
+ ```
789
+
790
+ ### email_field
791
+
792
+ Our `email_field` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-email_field).
793
+
794
+ ![email_field](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/a9b61ca1-7eb9-47e4-9bb0-db9f964186e7)
795
+
796
+ ```erb
797
+ <%= form.email_field :email %>
798
+ ```
799
+
800
+ This generates the following HTML:
801
+
802
+ ```html
803
+ <div class="mb-3">
804
+ <label class="form-label required" for="user_email">Email address</label>
805
+ <input class="form-control" aria-required="true" required="required" type="email" name="user[email]" id="user_email">
806
+ </div>
807
+ ```
808
+
809
+ ### file_field
810
+
811
+ Our `file_field` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-file_field).
812
+
813
+ ![file_field](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/d9d41696-b2aa-43f7-9698-d6c339b01de0)
814
+
815
+ ```erb
816
+ <%= form.file_field :avatar %>
817
+ ```
818
+
819
+ This generates the following HTML:
820
+
821
+ ```html
822
+ <div class="mb-3">
823
+ <label class="form-label" for="user_avatar">Avatar</label>
824
+ <input class="form-control" type="file" name="user[avatar]" id="user_avatar">
825
+ </div>
826
+ ```
827
+
828
+ ### hidden_field
829
+
830
+ The `hidden_field` helper in `rails_bootstrap_form` calls the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-hidden_field) directly, and does no additional mark-up.
831
+
832
+ ### month_field
833
+
834
+ Our `month_field` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-month_field).
835
+
836
+ ![month_field](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/39627509-fd90-425b-b4c5-b0a2afdb59ae)
837
+
838
+ ```erb
839
+ <%= form.month_field :birth_month %>
840
+ ```
841
+
842
+ This generates the following HTML:
843
+
844
+ ```html
845
+ <div class="mb-3">
846
+ <label class="form-label" for="user_birth_month">Birth month</label>
847
+ <input class="form-control" type="month" name="user[birth_month]" id="user_birth_month">
848
+ </div>
849
+ ```
850
+
851
+ ### number_field
852
+
853
+ Our `number_field` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-number_field).
854
+
855
+ ![number_field](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/c9018601-991d-4589-bcc1-1a8fb3dc9c18)
856
+
857
+ ```erb
858
+ <%= form.number_field :expected_ctc %>
859
+ ```
860
+
861
+ This generates the following HTML:
862
+
863
+ ```html
864
+ <div class="mb-3">
865
+ <label class="form-label" for="user_expected_ctc">Expected CTC</label>
866
+ <input class="form-control" type="number" name="user[expected_ctc]" id="user_expected_ctc">
867
+ </div>
868
+ ```
869
+
870
+ ### password_field
871
+
872
+ Our `password_field` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-password_field).
873
+
874
+ ![password_field](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/594696b4-a8b4-460d-a1ed-f27bc21bcbf0)
875
+
876
+ ```erb
877
+ <%= form.password_field :password %>
878
+ ```
879
+
880
+ This generates the following HTML:
881
+
882
+ ```html
883
+ <div class="mb-3">
884
+ <label class="form-label required" for="user_password">Password</label>
885
+ <input class="form-control" aria-required="true" required="required" type="password" name="user[password]" id="user_password">
886
+ </div>
887
+ ```
888
+
889
+ ### phone_field
890
+
891
+ Our `phone_field` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-phone_field).
892
+
893
+ ![phone_field](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/44f2acec-2a01-4715-a26e-0ff98653fbaf)
894
+
895
+ ```erb
896
+ <%= form.phone_field :mobile_number %>
897
+ ```
898
+
899
+ This generates the following HTML:
900
+
901
+ ```html
902
+ <div class="mb-3">
903
+ <label class="form-label required" for="user_mobile_number">Mobile number</label>
904
+ <input class="form-control" aria-required="true" required="required" type="tel" name="user[mobile_number]" id="user_mobile_number">
905
+ </div>
906
+ ```
907
+
908
+ ### radio_button
909
+
910
+ Our `radio_button` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-radio_button).
911
+ This helper will render check box and label for you.
912
+
913
+ ![radio_button](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/9afa4065-6eea-44a6-a5be-d2936d1d2f9c)
914
+
915
+ ```erb
916
+ <%= form.radio_button :gender, :male, bootstrap_form: {label_text: "Male"} %>
917
+ ```
918
+
919
+ This generates the following HTML:
920
+
921
+ ```html
922
+ <div class="form-check mb-3">
923
+ <input class="form-check-input" type="radio" value="male" name="user[gender]" id="user_gender_male">
924
+ <label class="form-check-label" for="user_gender_male">Male</label>
925
+ </div>
926
+ ```
927
+
928
+ This helper also renders help text if `help_text` option is set or information of the field is added to the locale file:
929
+
930
+ ![radio_button_help_text](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/2409e822-c1bd-499b-b80f-e2948acf3403)
931
+
932
+ ```erb
933
+ <%= form.radio_button :gender, :male, bootstrap_form: {label_text: "Male", help_text: "Please select your gender"} %>
934
+ ```
935
+
936
+ This generates the following HTML:
937
+
938
+ ```html
939
+ <div class="form-check mb-3">
940
+ <input class="form-check-input" type="radio" value="male" name="user[gender]" id="user_gender_male">
941
+ <label class="form-check-label" for="user_gender_male">Male</label>
942
+ <div class="form-text text-muted">Please select your gender</div>
943
+ </div>
944
+ ```
945
+
946
+ ### range_field
947
+
948
+ Our `range_field` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-range_field).
949
+
950
+ ![range_field](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/7173d6fe-9b6f-4d80-8a48-37e86e025661)
951
+
952
+ ```erb
953
+ <%= form.range_field :excellence %>
954
+ ```
955
+
956
+ This generates the following HTML:
957
+
958
+ ```html
959
+ <div class="mb-3">
960
+ <label class="form-label" for="user_excellence">Excellence</label>
961
+ <input class="form-range" type="range" name="user[excellence]" id="user_excellence">
962
+ </div>
963
+ ```
964
+
965
+ ### search_field
966
+
967
+ Our `search_field` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-search_field).
968
+
969
+ ![search_field](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/b108c5d6-42b3-4fde-9717-dbb1cb8b8780)
970
+
971
+ ```erb
972
+ <%= form.search_field :search %>
973
+ ```
974
+
975
+ This generates the following HTML:
976
+
977
+ ```html
978
+ <div class="mb-3">
979
+ <label class="form-label" for="user_search">Search</label>
980
+ <input class="form-control" type="search" name="user[search]" id="user_search">
981
+ </div>
982
+ ```
983
+
984
+ ### telephone_field
985
+
986
+ Our `telephone_field` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-telephone_field).
987
+
988
+ ![telephone_field](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/0f8ded9b-4dc5-4dea-9d3e-c8850776a0d4)
989
+
990
+ ```erb
991
+ <%= form.telephone_field :mobile_number %>
992
+ ```
993
+
994
+ This generates the following HTML:
995
+
996
+ ```html
997
+ <div class="mb-3">
998
+ <label class="form-label required" for="user_mobile_number">Mobile number</label>
999
+ <input class="form-control" aria-required="true" required="required" type="tel" name="user[mobile_number]" id="user_mobile_number">
1000
+ </div>
1001
+ ```
1002
+
1003
+ ### text_field
1004
+
1005
+ Our `text_field` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-text_field).
1006
+
1007
+ ![text_field](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/88bc6eb0-53a6-4f5a-8dce-8499e6b2259d)
1008
+
1009
+ ```erb
1010
+ <%= form.text_field :name %>
1011
+ ```
1012
+
1013
+ This generates the following HTML:
1014
+
1015
+ ```html
1016
+ <div class="mb-3">
1017
+ <label class="form-label required" for="user_name">Name</label>
1018
+ <input class="form-control" aria-required="true" required="required" type="text" name="user[name]" id="user_name">
1019
+ </div>
1020
+ ```
1021
+
1022
+ ### text_area
1023
+
1024
+ Our `text_area` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-text_area).
1025
+
1026
+ ![text_area](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/3dad9907-4cd1-4144-a596-2471cce3739b)
1027
+
1028
+ ```erb
1029
+ <%= form.text_area :street %>
1030
+ ```
1031
+
1032
+ This generates the following HTML:
1033
+
1034
+ ```html
1035
+ <div class="mb-3">
1036
+ <label class="form-label required" for="user_street">Street</label>
1037
+ <textarea class="form-control" aria-required="true" required="required" name="user[street]" id="user_street"></textarea>
1038
+ </div>
1039
+ ```
1040
+
1041
+ ### time_field
1042
+
1043
+ Our `time_field` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-time_field).
1044
+
1045
+ ![time_field](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/cbf1a798-acc5-49a9-94d3-f3462f15ebc9)
1046
+
1047
+ ```erb
1048
+ <%= form.time_field :interview_time %>
1049
+ ```
1050
+
1051
+ This generates the following HTML:
1052
+
1053
+ ```html
1054
+ <div class="mb-3">
1055
+ <label class="form-label" for="user_interview_time">Interview time</label>
1056
+ <input class="form-control" type="time" name="user[interview_time]" id="user_interview_time">
1057
+ </div>
1058
+ ```
1059
+
1060
+ ### url_field
1061
+
1062
+ Our `url_field` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-url_field).
1063
+
1064
+ ![url_field](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/dfb8a3ab-a1b2-4ce8-a10b-619b3fb1a268)
1065
+
1066
+ ```erb
1067
+ <%= form.url_field :blog_url %>
1068
+ ```
1069
+
1070
+ This generates the following HTML:
1071
+
1072
+ ```html
1073
+ <div class="mb-3">
1074
+ <label class="form-label" for="user_blog_url">Blog URL</label>
1075
+ <input class="form-control" type="url" name="user[blog_url]" id="user_blog_url">
1076
+ </div>
1077
+ ```
1078
+
1079
+ ### week_field
1080
+
1081
+ Our `week_field` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-week_field).
1082
+
1083
+ ![week_field](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/609d0c59-c5ff-497c-8461-fc289ab06d6f)
1084
+
1085
+ ```erb
1086
+ <%= form.week_field :winter_holiday_week %>
1087
+ ```
1088
+
1089
+ This generates the following HTML:
1090
+
1091
+ ```html
1092
+ <div class="mb-3">
1093
+ <label class="form-label" for="user_winter_holiday_week">Winter holiday week</label>
1094
+ <input class="form-control" type="week" name="user[winter_holiday_week]" id="user_winter_holiday_week">
1095
+ </div>
1096
+ ```
1097
+
1098
+ ## Form Options Helpers
1099
+
1100
+ Our form options helpers accept the same arguments as the default Rails form options helpers.
1101
+ In order to apply addition options of `rails_bootstrap_form`, `bootstrap_form` object is passed in `options` argument of the helper.
1102
+ Here's an example of how you pass the arguments for each form option helper:
1103
+
1104
+ ### select
1105
+
1106
+ Our `select` helper accepts the same arguments as the [default Rails helper](http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-select).
1107
+ Here's an example of how you pass both options and html_options hashes:
1108
+
1109
+ ![select](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/e21f092c-d439-4817-bba1-8ec0c21330c1)
1110
+
1111
+ ```erb
1112
+ <%= form.select :fruit_id, options_for_select(::Fruit.pluck(:name, :id), form.object.fruit_id), {include_blank: "Select fruit", bootstrap_form: {size: :sm, help_text: false}}, {onchange: "this.form.submit();"} %>
1113
+ ```
1114
+
1115
+ This generates the following HTML:
1116
+
1117
+ ```html
1118
+ <div class="mb-3">
1119
+ <label class="form-label required" for="user_fruit_id">Favorite fruit</label>
1120
+ <select onchange="this.form.submit();" class="form-select" aria-required="true" required="required" name="user[fruit_id]" id="user_fruit_id">
1121
+ <option value="">Select fruit</option>
1122
+ <option value="1">Mango</option>
1123
+ <option value="2">Apple</option>
1124
+ <option value="3">Orange</option>
1125
+ <option value="4">Watermelon</option>
1126
+ </select>
1127
+ </div>
1128
+ ```
1129
+
1130
+ ### collection_select
1131
+
1132
+ Our `collection_select` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select).
1133
+ Here's an example of how you pass both options and html_options hashes:
1134
+
1135
+ ![collection_select](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/c3a24265-81a9-4d1b-aa01-2b066d2f8bc7)
1136
+
1137
+ ```erb
1138
+ <%= form.collection_select :fruit_id, ::Fruit.all, :id, :name, {include_blank: "Select fruit", bootstrap_form: {help_text: false}}, {selected: form.object.fruit_id, onchange: "this.form.submit();"} %>
1139
+ ```
1140
+
1141
+ This generates the following HTML:
1142
+
1143
+ ```html
1144
+ <div class="mb-3">
1145
+ <label class="form-label required" for="user_fruit_id">Favorite fruit</label>
1146
+ <select onchange="this.form.submit();" class="form-select" aria-required="true" required="required" name="user[fruit_id]" id="user_fruit_id">
1147
+ <option value="">Select fruit</option>
1148
+ <option value="1">Mango</option>
1149
+ <option value="2">Apple</option>
1150
+ <option value="3">Orange</option>
1151
+ <option value="4">Watermelon</option>
1152
+ </select>
1153
+ </div>
1154
+ ```
1155
+
1156
+ ### grouped_collection_select
1157
+
1158
+ Our `grouped_collection_select` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-grouped_collection_select).
1159
+ Here's an example of how you pass both options and html_options hashes:
1160
+
1161
+ ![grouped_collection_select](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/d8f90065-3aa8-4d52-9c3e-0486324b3624)
1162
+
1163
+ ```erb
1164
+ <%= form.grouped_collection_select :city, ::Country.includes(:cities), :cities, :name, :id, :name, {include_blank: "Select city", bootstrap_form: {floating: true}}, {onchange: "this.form.submit();"} %>
1165
+ ```
1166
+
1167
+ This generates the following HTML:
1168
+
1169
+ ```html
1170
+ <div class="mb-3">
1171
+ <div class="form-floating">
1172
+ <select onchange="this.form.submit();" class="form-select" aria-required="true" required="required" placeholder="City" name="user[city]" id="user_city">
1173
+ <option value="">Select city</option>
1174
+ <optgroup label="India">
1175
+ <option value="1">Mumbai</option>
1176
+ <option value="2">New Delhi</option>
1177
+ <option value="3">Kolkata</option>
1178
+ <option value="4">Chennai</option>
1179
+ </optgroup>
1180
+ <optgroup label="Ireland">
1181
+ <option value="5">Dublin</option>
1182
+ <option value="6">Galway</option>
1183
+ <option value="7">Cork</option>
1184
+ <option value="8">Belfast</option>
1185
+ </optgroup>
1186
+ <optgroup label="United States">
1187
+ <option value="9">New York</option>
1188
+ <option value="10">Los Angeles</option>
1189
+ <option value="11">San Francisco</option>
1190
+ <option value="12">Chicago</option>
1191
+ </optgroup>
1192
+ ...
1193
+ ...
1194
+ </select>
1195
+ <label class="form-label required" for="user_city">City</label>
1196
+ </div>
1197
+ </div>
1198
+ ```
1199
+
1200
+ ### time_zone_select
1201
+
1202
+ Our `time_zone_select` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-time_zone_select).
1203
+ Here's an example of how you pass both options and html_options hashes:
1204
+
1205
+ ![time_zone_select](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/e161585c-1bbf-485c-9baf-c57b15258fe8)
1206
+
1207
+ ```erb
1208
+ <%= form.time_zone_select :timezone, ::ActiveSupport::TimeZone.all, {include_blank: "Select time zone", bootstrap_form: {label_text: "Preferred time zone"}}, {onchange: "this.form.submit();"} %>
1209
+ ```
1210
+
1211
+ This generates the following HTML:
1212
+
1213
+ ```html
1214
+ <div class="mb-3">
1215
+ <label class="form-label" for="user_timezone">Preferred time zone</label>
1216
+ <select onchange="this.form.submit();" class="form-select" name="user[timezone]" id="user_timezone">
1217
+ <option value="">Select time zone</option>
1218
+ <option value="International Date Line West">(GMT-12:00) International Date Line West</option>
1219
+ <option value="American Samoa">(GMT-11:00) American Samoa</option>
1220
+ <option value="Midway Island">(GMT-11:00) Midway Island</option>
1221
+ <option value="Hawaii">(GMT-10:00) Hawaii</option>
1222
+ <option value="Alaska">(GMT-09:00) Alaska</option>
1223
+ <option value="Pacific Time (US &amp; Canada)">(GMT-08:00) Pacific Time (US &amp; Canada)</option>
1224
+ <option value="Tijuana">(GMT-08:00) Tijuana</option>
1225
+ <option value="Arizona">(GMT-07:00) Arizona</option>
1226
+ ...
1227
+ ...
1228
+ </select>
1229
+ </div>
1230
+ ```
1231
+
1232
+ ### weekday_select
1233
+
1234
+ Our `weekday_select` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-weekday_select).
1235
+ Here's an example of how you pass both options and html_options hashes:
1236
+
1237
+ ![weekday_select](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/e469a57d-3d22-4c9e-829b-4ba825593ae1)
1238
+
1239
+ ```erb
1240
+ <%= form.weekday_select :weekly_off, {selected: "Monday", bootstrap_form: {label_text: "Week off"}}, {onchange: "this.form.submit();} %>
1241
+ ```
1242
+
1243
+ This generates the following HTML:
1244
+
1245
+ ```html
1246
+ <div class="mb-3">
1247
+ <label class="form-label" for="user_weekly_off">Week off</label>
1248
+ <select onchange="this.form.submit();" class="form-select" name="user[weekly_off]" id="user_weekly_off">
1249
+ <option selected="selected" value="Monday">Monday</option>
1250
+ <option value="Tuesday">Tuesday</option>
1251
+ <option value="Wednesday">Wednesday</option>
1252
+ <option value="Thursday">Thursday</option>
1253
+ <option value="Friday">Friday</option>
1254
+ <option value="Saturday">Saturday</option>
1255
+ <option value="Sunday">Sunday</option>
1256
+ </select>
1257
+ </div>
1258
+ ```
1259
+
1260
+ ### collection_check_boxes
1261
+
1262
+ This helper provides a way to create collection of check boxes. This helper accepts same arguments as [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_check_boxes) except it don't accept a block as
1263
+ an argument and takes care of rendering labels, check boxes, and wrapper for you.
1264
+
1265
+ ![collection_check_boxes](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/c92f5921-e572-4384-812e-31308e018f66)
1266
+
1267
+ ```erb
1268
+ <%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name, {bootstrap_form: {layout: :horizontal}, onchange: "this.form.submit();"}, {} %>
1269
+ ```
1270
+
1271
+ This generates the following HTML:
1272
+
1273
+ ```html
1274
+ <div class="row mb-3">
1275
+ <label class="col-form-label col-sm-2 required" for="user_skill_ids">Skills</label>
1276
+ <div class="col-sm-10">
1277
+ <div class="rails-bootstrap-forms-collection-check-boxes">
1278
+ <input value="" multiple="multiple" autocomplete="off" type="hidden" name="user[skill_ids][]" id="user_skill_ids">
1279
+ <div class="form-check form-check-inline">
1280
+ <input onchange="this.form.submit();" class="form-check-input" type="checkbox" value="1" name="user[skill_ids][]" id="user_skill_ids_1">
1281
+ <label class="form-check-label" for="user_skill_ids_1">Communication</label>
1282
+ </div>
1283
+ <div class="form-check form-check-inline">
1284
+ <input onchange="this.form.submit();" class="form-check-input" type="checkbox" value="2" name="user[skill_ids][]" id="user_skill_ids_2">
1285
+ <label class="form-check-label" for="user_skill_ids_2">Problem Solving</label>
1286
+ </div>
1287
+ <div class="form-check form-check-inline">
1288
+ <input onchange="this.form.submit();" class="form-check-input" type="checkbox" value="3" name="user[skill_ids][]" id="user_skill_ids_3">
1289
+ <label class="form-check-label" for="user_skill_ids_3">Leadership</label>
1290
+ </div>
1291
+ <div class="form-check form-check-inline">
1292
+ <input onchange="this.form.submit();" class="form-check-input" type="checkbox" value="4" name="user[skill_ids][]" id="user_skill_ids_4">
1293
+ <label class="form-check-label" for="user_skill_ids_4">Writing</label>
1294
+ </div>
1295
+ <div class="form-check form-check-inline">
1296
+ <input onchange="this.form.submit();" class="form-check-input" type="checkbox" value="5" name="user[skill_ids][]" id="user_skill_ids_5">
1297
+ <label class="form-check-label" for="user_skill_ids_5">Creativity</label>
1298
+ </div>
1299
+ <div class="form-check form-check-inline">
1300
+ <input onchange="this.form.submit();" class="form-check-input" type="checkbox" value="6" name="user[skill_ids][]" id="user_skill_ids_6">
1301
+ <label class="form-check-label" for="user_skill_ids_6">Time Management</label>
1302
+ </div>
1303
+ <div class="form-check form-check-inline">
1304
+ <input onchange="this.form.submit();" class="form-check-input" type="checkbox" value="7" name="user[skill_ids][]" id="user_skill_ids_7">
1305
+ <label class="form-check-label" for="user_skill_ids_7">Team Work</label>
1306
+ </div>
1307
+ <div class="form-check form-check-inline">
1308
+ <input onchange="this.form.submit();" class="form-check-input" type="checkbox" value="8" name="user[skill_ids][]" id="user_skill_ids_8">
1309
+ <label class="form-check-label" for="user_skill_ids_8">Negotiation</label>
1310
+ </div>
1311
+ <div class="form-check form-check-inline">
1312
+ <input onchange="this.form.submit();" class="form-check-input" type="checkbox" value="9" name="user[skill_ids][]" id="user_skill_ids_9">
1313
+ <label class="form-check-label" for="user_skill_ids_9">Decision Making</label>
1314
+ </div>
1315
+ <div class="form-check form-check-inline">
1316
+ <input onchange="this.form.submit();" class="form-check-input" type="checkbox" value="10" name="user[skill_ids][]" id="user_skill_ids_10">
1317
+ <label class="form-check-label" for="user_skill_ids_10">Management</label>
1318
+ </div>
1319
+ </div>
1320
+ <div class="form-text text-muted">Select your strong skills</div>
1321
+ </div>
1322
+ </div>
1323
+ ```
1324
+
1325
+ ### collection_radio_buttons
1326
+
1327
+ This helper provides a way to create collection of radio buttons. This helper accepts same arguments as [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_radio_buttons) except it don't accept a block as
1328
+ an argument and takes care of rendering labels, radio button, and wrapper for you.
1329
+
1330
+ ![collection_radio_buttons](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/798a8b0c-915a-40b1-9874-dd74f50d3695)
1331
+
1332
+ ```erb
1333
+ <%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {checked: form.object.fruit_id, bootstrap_form: {layout: :horizontal}}, {} %>
1334
+ ```
1335
+
1336
+ This generates the following HTML:
1337
+
1338
+ ```html
1339
+ <div class="row mb-3">
1340
+ <label class="col-form-label col-sm-2 required" for="user_fruit_id">Favorite fruit</label>
1341
+ <div class="col-sm-10">
1342
+ <div class="rails-bootstrap-forms-collection-radio-buttons">
1343
+ <div class="form-check form-check-inline">
1344
+ <input class="form-check-input" type="radio" value="1" name="user[fruit_id]" id="user_fruit_id_1">
1345
+ <label class="form-check-label" for="user_fruit_id_1">Mango</label>
1346
+ </div>
1347
+ <div class="form-check form-check-inline">
1348
+ <input class="form-check-input" type="radio" value="2" name="user[fruit_id]" id="user_fruit_id_2">
1349
+ <label class="form-check-label" for="user_fruit_id_2">Apple</label>
1350
+ </div>
1351
+ <div class="form-check form-check-inline">
1352
+ <input class="form-check-input" type="radio" value="3" name="user[fruit_id]" id="user_fruit_id_3">
1353
+ <label class="form-check-label" for="user_fruit_id_3">Orange</label>
1354
+ </div>
1355
+ <div class="form-check form-check-inline">
1356
+ <input class="form-check-input" type="radio" value="4" name="user[fruit_id]" id="user_fruit_id_4">
1357
+ <label class="form-check-label" for="user_fruit_id_4">Watermelon</label>
1358
+ </div>
1359
+ </div>
1360
+ <div class="form-text text-muted">Select your favorite fruit</div>
1361
+ </div>
1362
+ </div>
1363
+ ```
1364
+
1365
+ ## Date Helpers
1366
+
1367
+ The multiple selects that the date and time helpers (`date_select`, `time_select`, `datetime_select`) generate are wrapped inside a `fieldset.rails-bootstrap-forms-[date|time|datetime]-select` tag.
1368
+ This is because Bootstrap automatically styles our controls as blocks. This wrapper fixes this defining these selects as `inline-block` and a width of `auto`.
1369
+ In order to apply addition options of `rails_bootstrap_form`, `bootstrap_form` object is passed in `options` argument of the helper.
1370
+
1371
+ ### date_select
1372
+
1373
+ Our `date_select` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-date_select).
1374
+ Here's an example of how you pass both options and html_options hashes:
1375
+
1376
+ ![date_select](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/45fe5d72-43da-498e-a1c2-ac6729446bba)
1377
+
1378
+ ```erb
1379
+ <%= form.date_select :interview_date, {selected: form.object.interview_date, bootstrap_form: {label_text: "Choose interview date"}}, {onchange: "this.form.submit();"} %>
1380
+ ```
1381
+
1382
+ This generates the following HTML:
1383
+
1384
+ ```html
1385
+ <div class="mb-3">
1386
+ <label class="form-label" for="user_interview_date">Choose interview date</label>
1387
+ <fieldset class="rails-bootstrap-forms-date-select">
1388
+ <select id="user_interview_date_1i" name="user[interview_date(1i)]" onchange="this.form.submit();" class="form-select">
1389
+ <option value="2018">2018</option>
1390
+ <option value="2019">2019</option>
1391
+ <option value="2020">2020</option>
1392
+ <option value="2021">2021</option>
1393
+ <option value="2022">2022</option>
1394
+ <option value="2023" selected="selected">2023</option>
1395
+ ...
1396
+ ...
1397
+ </select>
1398
+ <select id="user_interview_date_2i" name="user[interview_date(2i)]" onchange="this.form.submit();" class="form-select">
1399
+ <option value="1">January</option>
1400
+ <option value="2">February</option>
1401
+ <option value="3">March</option>
1402
+ <option value="4">April</option>
1403
+ <option value="5" selected="selected">May</option>
1404
+ ...
1405
+ ...
1406
+ </select>
1407
+ <select id="user_interview_date_3i" name="user[interview_date(3i)]" onchange="this.form.submit();" class="form-select">
1408
+ <option value="1">1</option>
1409
+ <option value="2">2</option>
1410
+ <option value="3">3</option>
1411
+ <option value="4">4</option>
1412
+ <option value="5">5</option>
1413
+ <option value="6">6</option>
1414
+ <option value="7">7</option>
1415
+ <option value="8" selected="selected">8</option>
1416
+ ...
1417
+ ...
1418
+ </select>
1419
+ </fieldset>
1420
+ </div>
1421
+ ```
1422
+
1423
+ ### time_select
1424
+
1425
+ Our `time_select` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-time_select).
1426
+ Here's an example of how you pass both options and html_options hashes:
1427
+
1428
+ ![time_select](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/2195922c-c7cc-48dc-9912-3ef3cbb8e017)
1429
+
1430
+ ```erb
1431
+ <%= form.time_select :interview_time, {selected: form.object.interview_time, bootstrap_form: {label_text: "Choose interview time"}}, {onchange: "this.form.submit();"} %>
1432
+ ```
1433
+
1434
+ This generates the following HTML:
1435
+
1436
+ ```html
1437
+ <div class="mb-3">
1438
+ <label class="form-label" for="user_interview_time">Choose interview time</label>
1439
+ <fieldset class="rails-bootstrap-forms-time-select">
1440
+ <input type="hidden" id="user_interview_time_1i" name="user[interview_time(1i)]" value="1" autocomplete="off">
1441
+ <input type="hidden" id="user_interview_time_2i" name="user[interview_time(2i)]" value="1" autocomplete="off">
1442
+ <input type="hidden" id="user_interview_time_3i" name="user[interview_time(3i)]" value="1" autocomplete="off">
1443
+ <select id="user_interview_time_4i" name="user[interview_time(4i)]" onchange="this.form.submit();" class="form-select">
1444
+ <option value="00">00</option>
1445
+ <option value="01">01</option>
1446
+ <option value="02">02</option>
1447
+ <option value="03">03</option>
1448
+ <option value="04">04</option>
1449
+ ...
1450
+ ...
1451
+ </select>
1452
+ :
1453
+ <select id="user_interview_time_5i" name="user[interview_time(5i)]" onchange="this.form.submit();" class="form-select">
1454
+ <option value="00">00</option>
1455
+ <option value="01">01</option>
1456
+ <option value="02">02</option>
1457
+ <option value="03">03</option>
1458
+ <option value="04">04</option>
1459
+ <option value="05">05</option>
1460
+ ...
1461
+ ...
1462
+ </select>
1463
+ </fieldset>
1464
+ </div>
1465
+ ```
1466
+
1467
+ ### datetime_select
1468
+
1469
+ Our `datetime_select` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-datetime_select).
1470
+ Here's an example of how you pass both options and html_options hashes:
1471
+
1472
+ ![datetime_select](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/c0e0cd83-d44a-4308-bfa9-e25a2a488d66)
1473
+
1474
+ ```erb
1475
+ <%= form.datetime_select :interview_datetime, {selected: form.object.interview_datetime, bootstrap_form: {label_text: "Choose interview date & time"}}, {onchange: "this.form.submit();"} %>
1476
+ ```
1477
+
1478
+ This generates the following HTML:
1479
+
1480
+ ```html
1481
+ <div class="mb-3">
1482
+ <label class="form-label" for="user_interview_datetime">Choose interview date &amp; time</label>
1483
+ <fieldset class="rails-bootstrap-forms-datetime-select">
1484
+ <select id="user_interview_datetime_1i" name="user[interview_datetime(1i)]" onchange="this.form.submit();" class="form-select">
1485
+ <option value="2018">2018</option>
1486
+ <option value="2019">2019</option>
1487
+ <option value="2020">2020</option>
1488
+ <option value="2021">2021</option>
1489
+ ...
1490
+ ...
1491
+ </select>
1492
+ <select id="user_interview_datetime_2i" name="user[interview_datetime(2i)]" onchange="this.form.submit();" class="form-select">
1493
+ <option value="1">January</option>
1494
+ <option value="2">February</option>
1495
+ <option value="3">March</option>
1496
+ <option value="4">April</option>
1497
+ ...
1498
+ ...
1499
+ </select>
1500
+ <select id="user_interview_datetime_3i" name="user[interview_datetime(3i)]" onchange="this.form.submit();" class="form-select">
1501
+ <option value="1">1</option>
1502
+ <option value="2">2</option>
1503
+ <option value="3">3</option>
1504
+ <option value="4">4</option>
1505
+ <option value="5">5</option>
1506
+ <option value="6">6</option>
1507
+ ...
1508
+ ...
1509
+ </select>
1510
+
1511
+ <select id="user_interview_datetime_4i" name="user[interview_datetime(4i)]" onchange="this.form.submit();" class="form-select">
1512
+ <option value="00">00</option>
1513
+ <option value="01">01</option>
1514
+ <option value="02">02</option>
1515
+ <option value="03">03</option>
1516
+ <option value="04">04</option>
1517
+ ...
1518
+ ...
1519
+ </select>
1520
+ :
1521
+ <select id="user_interview_datetime_5i" name="user[interview_datetime(5i)]" onchange="this.form.submit();" class="form-select">
1522
+ <option value="00">00</option>
1523
+ <option value="01">01</option>
1524
+ <option value="02">02</option>
1525
+ <option value="03">03</option>
1526
+ <option value="04">04</option>
1527
+ ...
1528
+ ...
1529
+ </select>
1530
+ </fieldset>
1531
+ </div>
1532
+ ```
1533
+
1534
+ ## Submit Buttons
1535
+
1536
+ `rails_bootstrap_form` allows to easily create submit button for the form. `rails_bootstrap_form` supports three color variants for submit buttons: `secondary`, `primary`, and `danger`. Submit buttons are supported in `vertical`, `horizontal`, and `inline` layout.
1537
+ Submit buttons in inline form are wrapped inside `div.col-12` to properly render on small width devices.
1538
+
1539
+ ![button_helpers](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/f41a013b-b8c9-4689-a079-b8b102084cf0)
1540
+
1541
+ ```erb
1542
+ <%= form.secondary "Search" %>
1543
+ <%= form.primary "Register" %>
1544
+ <%= form.danger "Delete" %>
1545
+ ```
1546
+
1547
+ This generates the following HTML:
1548
+
1549
+ ```html
1550
+ <input type="submit" name="commit" value="Search" class="btn btn-secondary" data-disable-with="Search">
1551
+ <input type="submit" name="commit" value="Register" class="btn btn-primary" data-disable-with="Register">
1552
+ <input type="submit" name="commit" value="Delete" class="btn btn-danger" data-disable-with="Delete">
1553
+ ```
1554
+
1555
+ It is also possible to pass additional classes to the button helpers using HTML `class` attribute and that class will be
1556
+ added along with default class of the submit helper.
1557
+
1558
+ ![button_additional_class](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/d9493c36-5c18-4e2a-bb36-e8a947c16bfe)
1559
+
1560
+ ```erb
1561
+ <%= form.primary "Register", class: "register-button" %>
1562
+ ```
1563
+
1564
+ This generates the following HTML:
1565
+
1566
+ ```html
1567
+ <input type="submit" name="commit" value="Register" class="register-button btn btn-primary" data-disable-with="Register">
1568
+ ```
1569
+
1570
+ To render submit helper as a button helper, you can set `render_as_button` option to `true` or pass a block.
1571
+
1572
+ ![render_as_button](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/dffd72d8-3acf-4029-be04-3bf7776e8d9c)
1573
+
1574
+ ```erb
1575
+ <%= form.primary "Register", bootstrap_form: {render_as_button: true} %>
1576
+ <%= form.secondary do %>
1577
+ Sign in
1578
+ <% end %>
1579
+ ```
1580
+
1581
+ This generates the following HTML:
1582
+
1583
+ ```html
1584
+ <button name="button" type="submit" class="btn btn-primary">Register</button>
1585
+ <button name="button" type="submit" class="btn btn-secondary">
1586
+ Sign in
1587
+ </button>
1588
+ ```
1589
+
1590
+ ## Static controls
1591
+
1592
+ `rails_bootstrap_form` provides form helper `static_field` to render static controls which internally uses [text_field](#text_field) form helper.
1593
+ It sets `readonly` and `disabled` attributes on the text field. By default, `static_field` applies `form-control-plaintext`
1594
+ CSS class to the control but you can change it by using option `static_field_class`.
1595
+
1596
+ You can create a static controls like this:
1597
+
1598
+ ![static_field](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/cb7cc64f-c405-4abb-8ca9-66fe4c2fff98)
1599
+
1600
+ ```erb
1601
+ <%= form.static_field :email %>
1602
+ ```
1603
+
1604
+ This generates the following HTML:
1605
+
1606
+ ```html
1607
+ <div class="mb-3">
1608
+ <label class="form-label required" for="user_email">Email address</label>
1609
+ <input readonly="readonly" disabled="disabled" value="test@example.com" class="form-control-plaintext" aria-required="true" required="required" type="text" name="user[email]" id="user_email">
1610
+ </div>
1611
+ ```
1612
+
1613
+ ## Floating Labels
1614
+
1615
+ The `floating` option can be used to enable Bootstrap floating labels. This option is supported on text fields, text areas and dropdowns. Here's an example:
1616
+
1617
+ ![floating_labels](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/3976629d-4717-47b0-ab91-9a16e6c9ed5f)
1618
+
1619
+ ```erb
1620
+ <%= bootstrap_form_for @user, bootstrap_form: {floating: true} do |form| %>
1621
+ <%= form.text_field :name %>
1622
+ <%= form.email_field :username %>
1623
+ <%= form.password_field :password %>
1624
+ <%= form.fields_for :address, include_id: false do |address_form| %>
1625
+ <%= address_form.text_area :street %>
1626
+ <%= address_form.select :country_id, options_for_select(::Country.pluck(:name, :id), address_form.object.country_id),
1627
+ {include_blank: "Select Country"} %>
1628
+ <% end %>
1629
+ <%= form.primary "Register" %>
1630
+ <% end %>
1631
+ ```
1632
+
1633
+ This generates the following HTML:
1634
+
1635
+ ```html
1636
+ <form role="form" novalidate="novalidate" class="new_user" id="new_user" action="/users" accept-charset="UTF-8" method="post">
1637
+ <div class="mb-3">
1638
+ <div class="form-floating">
1639
+ <input class="form-control" aria-required="true" required="required" placeholder="Name" type="text" name="user[name]" id="user_name">
1640
+ <label class="form-label required" for="user_name">Name</label>
1641
+ </div>
1642
+ </div>
1643
+ <div class="mb-3">
1644
+ <div class="form-floating">
1645
+ <input class="form-control" placeholder="Username" type="email" name="user[username]" id="user_username">
1646
+ <label class="form-label" for="user_username">Username</label>
1647
+ </div>
1648
+ </div>
1649
+ <div class="mb-3">
1650
+ <div class="form-floating">
1651
+ <input class="form-control" aria-required="true" required="required" placeholder="Password" type="password" name="user[password]" id="user_password">
1652
+ <label class="form-label required" for="user_password">Password</label>
1653
+ </div>
1654
+ </div>
1655
+ <div class="mb-3">
1656
+ <div class="form-floating">
1657
+ <textarea class="form-control" aria-required="true" required="required" placeholder="Street" name="user[address_attributes][street]" id="user_address_attributes_street"></textarea>
1658
+ <label class="form-label required" for="user_address_attributes_street">Street</label>
1659
+ </div>
1660
+ </div>
1661
+ <div class="mb-3">
1662
+ <div class="form-floating">
1663
+ <select class="form-select" aria-required="true" required="required" placeholder="Country" name="user[address_attributes][country_id]" id="user_address_attributes_country_id">
1664
+ <option value="">Select Country</option>
1665
+ <option value="1">India</option>
1666
+ <option value="2">Ireland</option>
1667
+ <option value="3">United States</option>
1668
+ <option value="4">United Kingdom</option>
1669
+ </select>
1670
+ <label class="form-label required" for="user_address_attributes_country_id">Country</label>
1671
+ </div>
1672
+ </div>
1673
+ <input type="submit" name="commit" value="Register" class="btn btn-primary" data-disable-with="Register">
1674
+ </form>
1675
+ ```
1676
+
1677
+ ## Validation and Errors
1678
+
1679
+ By default, `rails_bootstrap_form` generations in-line errors which appear below the field.
1680
+
1681
+ ### Inline Errors
1682
+
1683
+ By default, fields that have validation errors will be outlined in red and the error will be displayed below the field. Here's an example:
1684
+
1685
+ ![inline_errors](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/a1cef10d-ba21-4d97-97e7-919691e2afe3)
1686
+
1687
+ ```erb
1688
+ <%= bootstrap_form_for @user do |form| %>
1689
+ <%= form.email_field :email %>
1690
+ <%= form.password_field :password %>
1691
+ <%= form.primary "Register" %>
1692
+ <% end %>
1693
+ ```
1694
+
1695
+ This generates the following HTML:
1696
+
1697
+ ```html
1698
+ <form role="form" novalidate="novalidate" class="new_user" id="new_user" action="/users" accept-charset="UTF-8" method="post">
1699
+ <div class="mb-3">
1700
+ <label class="form-label required is-invalid" for="user_email">Email address</label>
1701
+ <input class="form-control is-invalid" aria-required="true" required="required" type="email" name="user[email]" id="user_email">
1702
+ <div class="invalid-feedback">can't be blank</div>
1703
+ <div class="form-text text-muted">Please use official email address</div>
1704
+ </div>
1705
+ <div class="mb-3">
1706
+ <label class="form-label required is-invalid" for="user_password">Password</label>
1707
+ <input class="form-control is-invalid" aria-required="true" required="required" type="password" name="user[password]" id="user_password">
1708
+ <div class="invalid-feedback">can't be blank</div>
1709
+ </div>
1710
+ <input type="submit" name="commit" value="Register" class="btn btn-primary" data-disable-with="Register">
1711
+ </form>
1712
+ ```
1713
+
1714
+ ## Required Fields
1715
+
1716
+ A label that is associated with a mandatory field is automatically annotated with a `required` CSS class. `rails_bootstrap_form` provides styling for required fields.
1717
+ You're also free to add any appropriate CSS to style required fields as desired.
1718
+
1719
+ The label `required` class is determined based on the definition of a presence validator with the associated model attribute. Presently this is one of: `ActiveRecord::Validations::PresenceValidator` or `ActiveModel::Validations::PresenceValidator`.
1720
+
1721
+ In cases where this behaviour is undesirable, use the required option to force the class to be present or absent:
1722
+
1723
+ ![required_field](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/d99043f0-c382-4597-81bb-e96f27033e65)
1724
+
1725
+ ```
1726
+ <%= form.date_field :birth_date, required: false %>
1727
+ <%= form.url_field :blog_url, required: true %>
1728
+ ```
1729
+
1730
+ This generates the following HTML:
1731
+
1732
+ ```html
1733
+ <div class="mb-3">
1734
+ <label class="form-label" for="user_birth_date">Birth date</label>
1735
+ <input class="form-control" type="date" name="user[birth_date]" id="user_birth_date">
1736
+ </div>
1737
+ <div class="mb-3">
1738
+ <label class="form-label required" for="user_blog_url">Blog URL</label>
1739
+ <input required="required" class="form-control" aria-required="true" type="url" name="user[blog_url]" id="user_blog_url">
1740
+ </div>
1741
+ ```
1742
+
1743
+ ### Required `belongs_to` associations
1744
+
1745
+ Adding a form control for a `belongs_to` associated field will automatically pick up the associated presence validator.
1746
+
1747
+ ![belongs_to_presence](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/feb279d8-a742-42c2-b13d-8e5a0f60dfa2)
1748
+
1749
+ ```erb
1750
+ <%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {checked: form.object.fruit_id} %>
1751
+ ```
1752
+
1753
+ This generates the following HTML:
1754
+
1755
+ ```html
1756
+ <div class="mb-3">
1757
+ <label class="form-label required" for="user_fruit_id">Favorite fruit</label>
1758
+ <div class="rails-bootstrap-forms-collection-radio-buttons">
1759
+ <div class="form-check form-check-inline">
1760
+ <input class="form-check-input" type="radio" value="1" name="user[fruit_id]" id="user_fruit_id_1">
1761
+ <label class="form-check-label" for="user_fruit_id_1">Mango</label>
1762
+ </div>
1763
+ <div class="form-check form-check-inline">
1764
+ <input class="form-check-input" type="radio" value="2" name="user[fruit_id]" id="user_fruit_id_2">
1765
+ <label class="form-check-label" for="user_fruit_id_2">Apple</label>
1766
+ </div>
1767
+ <div class="form-check form-check-inline">
1768
+ <input class="form-check-input" type="radio" value="3" name="user[fruit_id]" id="user_fruit_id_3">
1769
+ <label class="form-check-label" for="user_fruit_id_3">Orange</label>
1770
+ </div>
1771
+ <div class="form-check form-check-inline">
1772
+ <input class="form-check-input" type="radio" value="4" name="user[fruit_id]" id="user_fruit_id_4">
1773
+ <label class="form-check-label" for="user_fruit_id_4">Watermelon</label>
1774
+ </div>
1775
+ </div>
1776
+ <div class="form-text text-muted">Select your favorite fruit</div>
1777
+ </div>
1778
+ ```
1779
+
1780
+ ## Internationalization
1781
+
1782
+ `rails_bootstrap_form` follows standard rails conventions so it's i18n-ready. See more [here](http://guides.rubyonrails.org/i18n.html#translations-for-active-record-models)
1783
+
1784
+ ## Other Tips
1785
+
1786
+ ### Empty But Visible Labels
1787
+
1788
+ Some third party plug-ins require an empty but visible label on an input control. The `hide_label` option generates a label that won't appear on the screen, but it's considered invisible and therefore doesn't work with such a plug-in. An empty label (e.g. `""`) causes the underlying Rails helpers to generate a label based on the field's attribute's name.
1789
+
1790
+ The solution is to use a zero-width character for the label, or some other "empty" HTML. For example:
1791
+
1792
+ ```erb
1793
+ bootstrap_form: {label_text: "&#8203;".html_safe}
1794
+ ```
1795
+
1796
+ or
1797
+
1798
+ ```erb
1799
+ bootstrap_form: {label_text: "<span></span>".html_safe}
1800
+ ```
1801
+
1802
+ ## Contributing
1803
+
1804
+ I welcome contributions. If you wish to contribute in `rails_bootstrap_form`, please review the [Contributing]() document first.
1805
+
1806
+ ## License
1807
+
1808
+ Copyright 2023 [Harshal V. LADHE](https://github.com/shivam091), Released under the MIT License