Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ div (field_with_errors), but this behavior is suppressed. Here's an example:
<div class="form-group">
<label class="form-control-label" for="user_email">Email</label>
<input class="form-control is-invalid" id="user_email" name="user[email]" type="email" value="">
<small class="invalid-feedback">can't be blank</small>
<small class="form-control-feedback">can't be blank</small>
</div>
```

Expand Down
8 changes: 4 additions & 4 deletions lib/bootstrap_form/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def form_group(*args, &block)
options[:class] = ["form-group", options[:class]].compact.join(' ')
options[:class] << " row" if get_group_layout(options[:layout]) == :horizontal
options[:class] << " form-inline" if field_inline_override?(options[:layout])
options[:class] << " #{feedback_class}" if options[:icon]
options[:class] << " #{error_class}" if has_error?(name)

content_tag(:div, options.except(:append, :id, :label, :help, :icon, :input_group_class, :label_col, :control_col, :layout, :prepend)) do
label = generate_label(options[:id], name, options[:label], options[:label_col], options[:layout]) if options[:label]
Expand Down Expand Up @@ -336,8 +336,8 @@ def control_class
"form-control"
end

def feedback_class
"has-feedback"
def error_class
'has-danger'
end

def control_specific_class(method)
Expand Down Expand Up @@ -475,7 +475,7 @@ def generate_label(id, name, options, custom_label_col, group_layout)
def generate_help(name, help_text)
if has_error?(name) && inline_errors
help_text = get_error_messages(name)
help_klass = 'invalid-feedback'
help_klass = 'form-control-feedback'
help_tag = :div
end
return if help_text == false
Expand Down
4 changes: 2 additions & 2 deletions test/bootstrap_fields_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ class BootstrapFieldsTest < ActionView::TestCase
expected = <<-HTML.strip_heredoc
<form accept-charset="UTF-8" action="/users" class="new_user" enctype="multipart/form-data" id="new_user" method="post" role="form">
<input name="utf8" type="hidden" value="&#x2713;"/>
<div class="form-group">
<div class="form-group has-danger">
<label for="user_misc">Misc</label>
<div class="custom-file">
<input class="custom-file-input is-invalid" id="user_misc" name="user[misc]" type="file" />
<label class="custom-file-label" for="user_misc">Choose file</label>
</div>
<div class="invalid-feedback">error for test</div>
<div class="form-control-feedback">error for test</div>
</div>
</form>
HTML
Expand Down
16 changes: 8 additions & 8 deletions test/bootstrap_form_group_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class BootstrapFormGroupTest < ActionView::TestCase
expected = <<-HTML.strip_heredoc
<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">
<div class="form-group has-danger">
<label class="required" for="user_email">Email</label>
<div class="input-group">
<div class="input-group-prepend">
Expand All @@ -164,7 +164,7 @@ class BootstrapFormGroupTest < ActionView::TestCase
<div class="input-group-append">
<span class="input-group-text">.00</span>
</div>
<div class="invalid-feedback">can't be blank, is too short (minimum is 5 characters)</span>
<div class="form-control-feedback">can't be blank, is too short (minimum is 5 characters)</span>
</div>
</div>
</form>
Expand Down Expand Up @@ -337,9 +337,9 @@ class BootstrapFormGroupTest < ActionView::TestCase
end

expected = <<-HTML.strip_heredoc
<div class="form-group">
<div class="form-group has-danger">
<p class="form-control-static">Bar</p>
<div class="invalid-feedback">can't be blank, is too short (minimum is 5 characters)</div>
<div class="form-control-feedback">can't be blank, is too short (minimum is 5 characters)</div>
</div>
HTML
assert_equivalent_xml expected, output
Expand All @@ -360,14 +360,14 @@ class BootstrapFormGroupTest < ActionView::TestCase
assert @user.invalid?

expected = <<-HTML.strip_heredoc
<div class="form-group none-margin">
<div class="form-group none-margin has-danger">
<div class="field_with_errors">
<label class="required" for="user_email">Email</label>
</div>
<div class="field_with_errors">
<input class="form-control is-invalid" id="user_email" name="user[email]" type="email" />
</div>
<div class="invalid-feedback">can't be blank, is too short (minimum is 5 characters)</div>
<div class="form-control-feedback">can't be blank, is too short (minimum is 5 characters)</div>
</div>
HTML
assert_equivalent_xml expected, @builder.email_field(:email, wrapper_class: 'none-margin')
Expand All @@ -384,10 +384,10 @@ class BootstrapFormGroupTest < ActionView::TestCase
expected = <<-HTML.strip_heredoc
<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 none-margin">
<div class="form-group none-margin has-danger">
<label class="required" for="user_email">Email</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 class="form-control-feedback">can't be blank, is too short (minimum is 5 characters)</div>
</div>
</form>
HTML
Expand Down
20 changes: 10 additions & 10 deletions test/bootstrap_form_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ class BootstrapFormTest < ActionView::TestCase
expected = <<-HTML.strip_heredoc
<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">
<div class="form-group has-danger">
<label class="required" 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>
Expand All @@ -423,10 +423,10 @@ class BootstrapFormTest < ActionView::TestCase
expected = <<-HTML.strip_heredoc
<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">
<div class="form-group has-danger">
<label class="required" 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 class="form-control-feedback">can't be blank, is too short (minimum is 5 characters)</span>
</div>
</form>
HTML
Expand All @@ -443,10 +443,10 @@ class BootstrapFormTest < ActionView::TestCase
expected = <<-HTML.strip_heredoc
<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">
<div class="form-group has-danger">
<label class="required" 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 class="form-control-feedback">can't be blank, is too short (minimum is 5 characters)</div>
</div>
</form>
HTML
Expand Down Expand Up @@ -637,10 +637,10 @@ class BootstrapFormTest < ActionView::TestCase
expected = <<-HTML.strip_heredoc
<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">
<div class="form-group has-danger">
<label class="required" for="user_email">Email</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 class="form-control-feedback">can't be blank, is too short (minimum is 5 characters)</div>
</div>
</form>
HTML
Expand All @@ -658,14 +658,14 @@ class BootstrapFormTest < ActionView::TestCase
expected = <<-HTML.strip_heredoc
<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post">
<input name="utf8" type="hidden" value="&#x2713;" />
<div class="form-group">
<div class="form-group has-danger">
<div class="field_with_errors">
<label class="required" for="user_email">Email</label>
</div>
<div class="field_with_errors">
<input class="form-control is-invalid" id="user_email" name="user[email]" type="text" />
</div>
<div class="invalid-feedback">can't be blank, is too short (minimum is 5 characters)</span>
<div class="form-control-feedback">can't be blank, is too short (minimum is 5 characters)</span>
</div>
</form>
HTML
Expand All @@ -683,7 +683,7 @@ class BootstrapFormTest < ActionView::TestCase
expected = <<-HTML.strip_heredoc
<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">
<div class="form-group has-danger">
<label class="required" for="user_email">Email</label>
<input class="form-control is-invalid" id="user_email" name="user[email]" type="text" />
<small class="form-text text-muted">This is required</small>
Expand Down
24 changes: 12 additions & 12 deletions test/bootstrap_selects_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
expected = <<-HTML.strip_heredoc
<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">
<div class="form-group has-danger">
<label for="user_misc">Misc</label>
<select class="form-control is-invalid" id="user_misc" name="user[misc]">#{time_zone_options_for_select}</select>
<div class="invalid-feedback">error for test</div>
<div class="form-control-feedback">error for test</div>
</div>
</form>
HTML
Expand Down Expand Up @@ -170,10 +170,10 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
expected = <<-HTML.strip_heredoc
<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">
<div class="form-group has-danger">
<label for="user_status">Status</label>
<select class="form-control is-invalid" id="user_status" name="user[status]"></select>
<div class="invalid-feedback">error for test</div>
<div class="form-control-feedback">error for test</div>
</div>
</form>
HTML
Expand Down Expand Up @@ -219,10 +219,10 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
expected = <<-HTML.strip_heredoc
<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">
<div class="form-group has-danger">
<label for="user_status">Status</label>
<select class="form-control is-invalid" id="user_status" name="user[status]"></select>
<div class="invalid-feedback">error for test</div>
<div class="form-control-feedback">error for test</div>
</div>
</form>
HTML
Expand Down Expand Up @@ -281,7 +281,7 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
expected = <<-HTML.strip_heredoc
<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">
<div class="form-group has-danger">
<label for="user_misc">Misc</label>
<div class="rails-bootstrap-forms-date-select">
<select class="form-control is-invalid" id="user_misc_1i" name="user[misc(1i)]">
Expand All @@ -294,7 +294,7 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
#{options_range(start: 1, stop: 31, selected: 3)}
</select>
</div>
<div class="invalid-feedback">error for test</div>
<div class="form-control-feedback">error for test</div>
</div>
</form>
HTML
Expand Down Expand Up @@ -382,7 +382,7 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
expected = <<-HTML.strip_heredoc
<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">
<div class="form-group has-danger">
<label for="user_misc">Misc</label>
<div class="rails-bootstrap-forms-time-select">
<input id="user_misc_1i" name="user[misc(1i)]" type="hidden" value="2012" />
Expand All @@ -396,7 +396,7 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
#{options_range(start: "00", stop: "59", selected: "00")}
</select>
</div>
<div class="invalid-feedback">error for test</div>
<div class="form-control-feedback">error for test</div>
</div>
</form>
HTML
Expand Down Expand Up @@ -490,7 +490,7 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
expected = <<-HTML.strip_heredoc
<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">
<div class="form-group has-danger">
<label for="user_misc">Misc</label>
<div class="rails-bootstrap-forms-datetime-select">
<select class="form-control is-invalid" id="user_misc_1i" name="user[misc(1i)]">
Expand All @@ -511,7 +511,7 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
#{options_range(start: "00", stop: "59", selected: "00")}
</select>
</div>
<div class="invalid-feedback">error for test</div>
<div class="form-control-feedback">error for test</div>
</div>
</form>
HTML
Expand Down