@@ -59,15 +59,17 @@ Then:
5959
6060` bundle install `
6161
62- ` bootstrap_form ` uses a very small number of its own CSS styles. Add the styles to your CSS bundle (usually your ` application.scss ` file). The way to do this depends on whether you're using Propshaft (the Rails 8 default), or Sprockets (pre-Rails 8). (Check your ` Gemfile ` to see whether you're using ` sprockets-rails ` or ` propshaft ` .)
62+ ` bootstrap_form ` uses a very small number of its own CSS styles. These styles are used in HTML generated by the ` error_summary ` and ` alert_message ` error helpers, and the ` date_select ` , ` time_select ` , and ` datetime_select ` helpers. If you're not using those helpers, you don't need to install the ` bootstrap_form ` CSS styles.
6363
64- If you're using Propshaft, add the styles like this:
64+ If you do need the CSS styles, add them to your CSS bundle (usually your ` application.scss ` file). The way to do this depends on whether you're using Propshaft (the Rails 8 default), or Sprockets (pre-Rails 8). (Check your ` Gemfile ` to see whether you're using ` sprockets-rails ` or ` propshaft ` .)
65+
66+ If you're using Propshaft, add the styles to your CSS bundle like this:
6567
6668``` scss
6769@use " rails_bootstrap_forms" ;
6870```
6971
70- If you're using Sprockets, add the styles like this:
72+ If you're using Sprockets, add the styles to your CSS bundle like this:
7173
7274``` scss
7375@import " rails_bootstrap_forms.css" ;
@@ -939,7 +941,25 @@ The value of the block would be used for the content of the static "control".
939941Bootstrap 4 actually creates and styles a disabled input field for static controls, so the value of the control has to be specified by the `value:` option.
940942Passing a block to `static_control` no longer has any effect.
941943
942- # # Date Helpers
944+ # # Date and Time Helpers
945+
946+ You can create a date picker, time picker, or date-time picker with `date_field`, `time_field`, or `datetime_field`, like this :
947+
948+ 
949+ ` ` ` erb
950+ <%= f.date_field :joined_at, class: "w-auto" % >
951+ ` ` `
952+
953+ This generates :
954+
955+ ` ` ` html
956+ <div class="mb-3">
957+ <label class="form-label" for="user_joined_at">Joined at</label>
958+ <input class="form-control w-auto" id="user_joined_at" name="user[joined_at]" type="date">
959+ </div>
960+ ` ` `
961+
962+ For backwards compatibility, there are also helpers for `date_select`, `time_select`, and `datetime_select`.
943963
944964The multiple selects that the date and time helpers (`date_select`,
945965` time_select` , `datetime_select`) generate are wrapped inside a
@@ -952,7 +972,7 @@ this by defining these selects as `inline-block` and a width of `auto`.
952972The `btn btn-secondary` CSS classes are automatically added to your submit
953973buttons.
954974
955- 
975+ 
956976` ` ` erb
957977<%= f.submit % >
958978` ` `
@@ -966,7 +986,7 @@ This generates:
966986You can also use the `primary` helper, which adds `btn btn-primary` to your
967987submit button :
968988
969- 
989+ 
970990` ` ` erb
971991<%= f.primary "Optional Label" % >
972992` ` `
@@ -979,7 +999,7 @@ This generates:
979999
9801000You can specify your own classes like this :
9811001
982- 
1002+ 
9831003` ` ` erb
9841004<%= f.submit "Log In", class: "btn btn-success" % >
9851005` ` `
@@ -995,7 +1015,7 @@ it will be rendered as an HTML button, instead of an input tag. This allows you
9951015to specify HTML content and styling for your buttons (such as adding
9961016illustrative icons to them). For example, the following statements
9971017
998- 
1018+ 
9991019` ` ` erb
10001020<%= f.primary "Save changes <span class='bi bi-save'></span>".html_safe, render_as_button: true % >
10011021
@@ -1029,7 +1049,7 @@ Bootstrap classes), or for element targeting via CSS classes.
10291049Be aware, however, that using the `class` option will discard any extra classes
10301050you add. As an example, the following button declarations
10311051
1032- 
1052+ 
10331053` ` ` erb
10341054<%= f.primary "My Nice Button", extra_class: 'my-button' % >
10351055
@@ -1047,7 +1067,7 @@ will be rendered as
10471067
10481068# # Rich Text Areas AKA Trix Editor
10491069
1050- 
1070+ 
10511071` ` ` erb
10521072<%= f.rich_text_area(:life_story) % >
10531073` ` `
@@ -1115,7 +1135,7 @@ The `hidden_field` helper in `bootstrap_form` calls the Rails helper directly, a
11151135If you want to use the original Rails form helpers for a particular field,
11161136append `_without_bootstrap` to the helper :
11171137
1118- 
1138+ 
11191139` ` ` erb
11201140<%= f.text_field_without_bootstrap :email % >
11211141` ` `
@@ -1137,7 +1157,7 @@ To use an inline-layout form, use the `layout: :inline` option. To hide labels,
11371157use the `hide_label : true` option, which keeps your labels accessible to those
11381158using screen readers.
11391159
1140- 
1160+ 
11411161` ` ` erb
11421162<%= bootstrap_form_for(@user, layout: :inline) do |f| % >
11431163 <%= f.email_field :email, hide_label: true % >
@@ -1174,7 +1194,7 @@ This generates:
11741194
11751195To skip label rendering at all, use `skip_label : true` option.
11761196
1177- 
1197+ 
11781198` ` ` erb
11791199<%= f.password_field :password, skip_label: true % >
11801200` ` `
@@ -1196,7 +1216,7 @@ To use a horizontal-layout form with labels to the left of the control, use the
11961216In the example below, the submit button has been wrapped in a `form_group` to
11971217keep it properly aligned.
11981218
1199- 
1219+ 
12001220` ` ` erb
12011221<%= bootstrap_form_for(@user, layout: :horizontal, label_col: "col-sm-2", control_col: "col-sm-10") do |f| % >
12021222 <%= f.email_field :email % >
@@ -1243,7 +1263,7 @@ This generates:
12431263
12441264The `label_col` and `control_col` css classes can also be changed per control :
12451265
1246- 
1266+ 
12471267` ` ` erb
12481268<%= bootstrap_form_for(@user, layout: :horizontal) do |f| % >
12491269 <%= f.email_field :email % >
@@ -1310,7 +1330,7 @@ end
13101330
13111331Control col wrapper class can be modified with `add_control_col_class`. This option will preserve column definition :
13121332
1313- 
1333+ 
13141334` ` ` erb
13151335<%= bootstrap_form_for(@user, layout: :horizontal) do |f| % >
13161336 <%= f.email_field :email % >
@@ -1349,7 +1369,7 @@ This generates:
13491369
13501370The form-level `layout` can be overridden per field, unless the form-level layout was `inline` :
13511371
1352- 
1372+ 
13531373` ` ` erb
13541374<%= bootstrap_form_for(@user, layout: :horizontal) do |f| % >
13551375 <%= f.email_field :email % >
@@ -1404,7 +1424,7 @@ A form-level `layout: :inline` can't be overridden because of the way Bootstrap
14041424The `floating` option can be used to enable Bootstrap 5's floating labels. This option is supported on text fields
14051425and dropdowns. Here's an example :
14061426
1407- 
1427+ 
14081428` ` ` erb
14091429<%= bootstrap_form_for(@user) do |f| % >
14101430 <%= f.email_field :email, floating: true % >
@@ -1452,7 +1472,7 @@ Rails normally wraps fields with validation errors in a `div.field_with_errors`,
14521472By default, fields that have validation errors will be outlined in red and the
14531473error will be displayed below the field. Here's an example :
14541474
1455- 
1475+ 
14561476` ` ` erb
14571477<%= bootstrap_form_for(@user_with_error) do |f| % >
14581478 <%= f.email_field :email % >
@@ -1519,7 +1539,7 @@ You can turn off inline errors for the entire form like this:
15191539You can also display validation errors in the field's label; just turn
15201540on the `:label_errors` option. Here's an example :
15211541
1522- 
1542+ 
15231543` ` ` erb
15241544<%= bootstrap_form_for(@user_with_error, label_errors: true) do |f| % >
15251545 <%= f.email_field :email % >
@@ -1552,7 +1572,7 @@ To display an error message with an error summary, you can use the
15521572` alert_message` helper. This won't output anything unless a model validation
15531573has failed.
15541574
1555- 
1575+ 
15561576` ` ` erb
15571577<%= bootstrap_form_for @user_with_error do |f| % >
15581578 <%= f.alert_message "Please fix the errors below." % >
@@ -1576,7 +1596,7 @@ Which outputs:
15761596
15771597You can turn off the error summary like this :
15781598
1579- 
1599+ 
15801600` ` ` erb
15811601<%= bootstrap_form_for @user_with_error do |f| % >
15821602 <%= f.alert_message "Please fix the errors below.", error_summary: false % >
@@ -1593,7 +1613,7 @@ This generates:
15931613
15941614To output a simple unordered list of errors, use the `error_summary` helper.
15951615
1596- 
1616+ 
15971617` ` ` erb
15981618<%= bootstrap_form_for @user_with_error do |f| % >
15991619 <%= f.error_summary % >
@@ -1616,7 +1636,7 @@ Which outputs:
16161636
16171637If you want to display a custom inline error for a specific attribute not represented by a form field, use the `errors_on` helper.
16181638
1619- 
1639+ 
16201640` ` ` erb
16211641<%= bootstrap_form_for @user_with_error do |f| % >
16221642 <input class="is-invalid" autocomplete="off" disabled type="hidden">
@@ -1637,7 +1657,7 @@ Note that the `invalid-feedback` `div` is hidden unless there is a preceding ele
16371657
16381658You can hide the attribute name like this :
16391659
1640- 
1660+ 
16411661` ` ` erb
16421662<%= bootstrap_form_for @user_with_error do |f| % >
16431663 <input class="is-invalid" autocomplete="off" disabled type="hidden">
@@ -1656,7 +1676,7 @@ Which outputs:
16561676
16571677You can also use a custom class for the wrapping div, like this :
16581678
1659- 
1679+ 
16601680` ` ` erb
16611681<%= bootstrap_form_for @user_with_error do |f| % >
16621682 <input class="is-invalid" autocomplete="off" disabled type="hidden">
@@ -1695,7 +1715,7 @@ ActiveModel::Validations::PresenceValidator.
16951715
16961716In cases where this behaviour is undesirable, use the `required` option to force the class to be present or absent :
16971717
1698- 
1718+ 
16991719` ` ` erb
17001720<%= f.password_field :login, label: "New Username", required: true % >
17011721<%= f.password_field :password, label: "New Password", required: false % >
@@ -1718,7 +1738,7 @@ This generates:
17181738
17191739Adding a form control for a `belongs_to` field will automatically pick up the associated presence validator.
17201740
1721- 
1741+ 
17221742` ` ` erb
17231743<%= bootstrap_form_for(@address, url: '/address') do |f| % >
17241744 <%= f.collection_select :user_id, @users, :id, :email, include_blank: "Select a value" % >
@@ -1765,7 +1785,7 @@ Generated HTML:
17651785
17661786Fields can be disabled using the standard Rails form helper option.
17671787
1768- 
1788+ 
17691789` ` ` erb
17701790<%= bootstrap_form_for @user do |f| % >
17711791 <div class="row g-3">
0 commit comments