Skip to content

Move validation errors for check boxes and radio buttons into last div.form-check.#448

Merged
mattbrictson merged 17 commits intobootstrap-ruby:masterfrom
lcreid:419-check-radio-errors-d
May 29, 2018
Merged

Move validation errors for check boxes and radio buttons into last div.form-check.#448
mattbrictson merged 17 commits intobootstrap-ruby:masterfrom
lcreid:419-check-radio-errors-d

Conversation

@lcreid
Copy link
Copy Markdown
Contributor

@lcreid lcreid commented Mar 8, 2018

Bootstrap 4 validation errors for groups of check boxes or radio buttons are supposed to be inside the <div class="form-check"> of the last check box or radio button in the group. See: https://getbootstrap.com/docs/4.0/components/forms/#supported-elements.

This is the third variation on a solution to this issue

See #436 (comment) and the comments that follow it for why we decided to take the approach in this PR.

This PR also includes a UPGRADE-4.0.md document describing breaking changes and work-arounds that result from this PR.

Fixes #418.

@lcreid lcreid added this to the 4.0.0 milestone Mar 8, 2018
@lcreid lcreid requested a review from mattbrictson March 8, 2018 03:46
Copy link
Copy Markdown
Contributor

@mattbrictson mattbrictson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. Thanks for introducing the UPGRADE doc in this PR; it should really help users of the gem.

I am going to resolve the conflicts and merge this in.

Comment thread test/bootstrap_form_group_test.rb Outdated
# </div>
# HTML
# assert_equivalent_xml expected, output
# end
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to remove this. It the comment served well for the review of this PR, but I would rather not keep comment-out code in the codebase. I'll move the reasoning for removing this into a commit comment instead.

@mattbrictson mattbrictson force-pushed the 419-check-radio-errors-d branch from 6d34088 to 9d73dd5 Compare May 29, 2018 00:22
This test case was removed as it was something that's too difficult to
support with Bootstrap 4.

    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

In its place, we've recommended a workaround in the UPGRADE-4.0 doc,
which is to output the error message manually. This workaround has a
corresponding test to verify its correctness.
@mattbrictson
Copy link
Copy Markdown
Contributor

@lcreid after rebasing this PR on the latest master, a test started failing. To get this PR passing I had to make the small change in the expected test output in commit 7c62989. Was this test failure legitimate? In which case a regression was introduced in this PR?

See test failure here: https://travis-ci.org/bootstrap-ruby/bootstrap_form/jobs/384966902#L913

@lcreid
Copy link
Copy Markdown
Contributor Author

lcreid commented May 29, 2018

@mattbrictson the correction you made to the test case is correct. I know the tests were all passing when I originally submitted the PR. My git-fu is not good enough for me to figure out how the test could have been passing when I originally submitted the pull request. (Actually, I have an idea how this happened, but I'll submit this comment and follow up later.)

The correction you made to the test case is in fact a change to the expected output that is a result of this PR. In other words, this PR changes the expected output, due to the way Bootstrap 4 works.

As I said, the code is all good the way it is right now.

@mattbrictson
Copy link
Copy Markdown
Contributor

Great! Thanks for double-checking 👍

@lcreid
Copy link
Copy Markdown
Contributor Author

lcreid commented May 29, 2018

FWIW: PR #454 fixed the validation error for horizontal forms. I must have broken the test case again somehow, although I still can't explain why Travis didn't complain until @mattbrictson did the final merge. At any rate, it's all right now.

@lcreid lcreid deleted the 419-check-radio-errors-d branch January 23, 2019 21:30
@suketk
Copy link
Copy Markdown

suketk commented Aug 25, 2022

Does this solve inline radio buttons? The formatting is wonky when you use error_message on the last radio.

Screen Shot 2022-08-25 at 7 09 33 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants