Skip to content

Commit

Permalink
Add text-danger to label when label_errors: true
Browse files Browse the repository at this point in the history
This maintains the appearance of label errors consistent with v2.7
(Bootstrap 3).
  • Loading branch information
lcreid committed Mar 9, 2018
1 parent ee605d7 commit 459e675
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/bootstrap_form/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ def generate_label(id, name, options, custom_label_col, group_layout)
if label_errors && has_error?(name)
error_messages = get_error_messages(name)
label_text = (options[:text] || object.class.human_attribute_name(name)).to_s.concat(" #{error_messages}")
options[:class] = [options[:class], "text-danger"].compact.join(" ")
label(name, label_text, options.except(:text))
else
label(name, options[:text], options.except(:text))
Expand Down
6 changes: 3 additions & 3 deletions test/bootstrap_form_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ class BootstrapFormTest < ActionView::TestCase
<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post" role="form">
<input name="utf8" type="hidden" value="&#x2713;" />
<div class="form-group">
<label class="required" for="user_email">Email can't be blank, is too short (minimum is 5 characters)</label>
<label class="required text-danger" for="user_email">Email can't be blank, is too short (minimum is 5 characters)</label>
<input class="form-control is-invalid" id="user_email" name="user[email]" type="text" />
</div>
</form>
Expand All @@ -424,7 +424,7 @@ class BootstrapFormTest < ActionView::TestCase
<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post" role="form">
<input name="utf8" type="hidden" value="&#x2713;" />
<div class="form-group">
<label class="required" for="user_email">Email can&#39;t be blank, is too short (minimum is 5 characters)</label>
<label class="required text-danger" for="user_email">Email can&#39;t be blank, is too short (minimum is 5 characters)</label>
<input class="form-control is-invalid" id="user_email" name="user[email]" type="text" />
<div class="invalid-feedback">can't be blank, is too short (minimum is 5 characters)</span>
</div>
Expand All @@ -444,7 +444,7 @@ class BootstrapFormTest < ActionView::TestCase
<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post" role="form">
<input name="utf8" type="hidden" value="&#x2713;" />
<div class="form-group">
<label class="required" for="user_email">Your e-mail address can&#39;t be blank, is too short (minimum is 5 characters)</label>
<label class="required text-danger" for="user_email">Your e-mail address can&#39;t be blank, is too short (minimum is 5 characters)</label>
<input class="form-control is-invalid" id="user_email" name="user[email]" type="text" />
<div class="invalid-feedback">can't be blank, is too short (minimum is 5 characters)</div>
</div>
Expand Down

0 comments on commit 459e675

Please sign in to comment.