-
Notifications
You must be signed in to change notification settings - Fork 355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move errors inside input-group and form-group. #422
Changes from all commits
42d2c5a
d7ef709
187aa69
b25ab77
463486e
9e66706
e83bf64
a2b4586
e48451d
b2d832a
073a1e3
844e133
ebab68a
0a73344
365dbf2
5cc7869
a15d06d
d12e146
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,6 +147,32 @@ class BootstrapFormGroupTest < ActionView::TestCase | |
assert_equivalent_xml expected, @builder.text_field(:email, prepend: '$', append: '.00') | ||
end | ||
|
||
test "adding both prepend and append text with validation error" do | ||
@user.email = nil | ||
assert @user.invalid? | ||
|
||
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="✓"/> | ||
<div class="form-group"> | ||
<label class="required" for="user_email">Email</label> | ||
<div class="input-group"> | ||
<div class="input-group-prepend"> | ||
<span class="input-group-text">$</div> | ||
</div> | ||
<input class="form-control is-invalid" id="user_email" name="user[email]" type="text" /> | ||
<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> | ||
</div> | ||
</form> | ||
HTML | ||
# TODO: We should build the @builder properly from `bootstrap_form_for`, so it's easier to test errors. | ||
assert_equivalent_xml expected, bootstrap_form_for(@user) { |f| f.text_field :email, prepend: '$', append: '.00' } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would render There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's how I started, but then it renders the default Rails error markup. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can put code used for error suppression (https://github.com/bootstrap-ruby/bootstrap_form/blob/master/lib/bootstrap_form/helper.rb#L45) into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good suggestion. In the spirit of limiting the scope of each PR, I continued to just tolerate a few extra lines of HTML in each test, but we should revisit the suggestion for easier error testing in another PR. |
||
end | ||
|
||
test "help messages for default forms" do | ||
expected = <<-HTML.strip_heredoc | ||
<div class="form-group"> | ||
|
@@ -303,22 +329,26 @@ class BootstrapFormGroupTest < ActionView::TestCase | |
assert_equivalent_xml expected, output | ||
end | ||
|
||
test 'form_group renders the "error" class and message corrrectly when object is invalid' do | ||
@user.email = nil | ||
assert @user.invalid? | ||
|
||
output = @builder.form_group :email do | ||
%{<p class="form-control-static">Bar</p>}.html_safe | ||
end | ||
|
||
expected = <<-HTML.strip_heredoc | ||
<div class="form-group"> | ||
<p class="form-control-static">Bar</p> | ||
<div class="invalid-feedback">can't be blank, is too short (minimum is 5 characters)</div> | ||
</div> | ||
HTML | ||
assert_equivalent_xml expected, output | ||
end | ||
# test 'form_group renders the "error" class and message corrrectly when object is invalid' do | ||
# # It could be said that the meaning of "form-group" has changed in Bootstrap 4, | ||
# # and that's why it shouldn't be outputting the error message anymore. Which | ||
# # would make this test case no longer valid. | ||
# # THIS TEST WAS REMOVED FROM v2.7. | ||
# @user.email = nil | ||
# assert @user.invalid? | ||
# | ||
# output = @builder.form_group :email do | ||
# %{<p class="form-control-static">Bar</p>}.html_safe | ||
# end | ||
# | ||
# expected = <<-HTML.strip_heredoc | ||
# <div class="form-group"> | ||
# <p class="form-control-static">Bar</p> | ||
# <div class="invalid-feedback">can't be blank, is too short (minimum is 5 characters)</div> | ||
# </div> | ||
# HTML | ||
# assert_equivalent_xml expected, output | ||
# end | ||
|
||
test "adds class to wrapped form_group by a field" do | ||
expected = <<-HTML.strip_heredoc | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this FIXME still valid? If so, could you clarify what additional cases need to be handled here?