Move validation errors for check and radio collections into last form-check div.#436
Move validation errors for check and radio collections into last form-check div.#436lcreid wants to merge 37 commits intobootstrap-ruby:masterfrom
Conversation
Added method for error and help and optionally prepend and append.
Some label code remains to be refactored.
Here's an example of a CHANGELOG.md entry (place it immediately under the * [#436](https://github.com/bootstrap-ruby/bootstrap_form/pull/436): Move validation errors for check and radio collections into last form-check div. - [@lcreid](https://github.com/lcreid).Generated by 🚫 Danger |
|
There are some hard problems here. I can't see how we can output Bootstrap 4 markup without requiring some users to change their code. I hope someone can guide me to what we should do. Sorry this is so convoluted, but I can't see a way to separate one issue from another. @mattbrictson @desheikh @donv any thoughts? BackgroundBootstrap 3 (v2.7)There are basically four use cases we're interested in:
Bootstrap 4The markup is different. The change that's causing grief is that check boxes and radio buttons are now rendered inside a
Possible SolutionsThese are not in any particular order of preference, effort, or any other criteria. A
This is the only option I can think of that avoids changing B
C
This solution is easy to document, i.e. the programmer just has to change all Internally, it's likely that D
This is pretty much the same as Solution C, except it requires the code changes for the "arbitrary text" use case, which I think might be the less common one compared to the "check box or radio button" use case. |
|
Thanks for digging into this one and documenting all the approaches. To be honest, none of the solutions feels right to me. Solution "A" is the most desirable end-user experience, but I think your intuition is correct that this is too heavy-handed. This might be a crazy idea, but can we solve this with just CSS? In other words, can we add our own styles that make the error messages appear even if we render the HTML the "wrong" way? Or perhaps a JS snippet that manipulates the DOM? Also: do we know if/how simple_form has dealt with this problem? Maybe that project has some ideas we can borrow. |
|
@mattbrictson your timing is perfect. I was just sitting down to charge off with Solution B, but the CSS idea is worth pursuing. I will look into it today. I'll also look at Just a note that I've spent some time looking at the Bootstrap 4 source. I think it confirms that some of the struggles are because Bootstrap 4 works in a fundamentally different way, and we may want to consider adopting the "Bootstrap 4 Way", at the expense of requiring more from programmers migrating from |
|
It looks like errors from check boxes and radio buttons in I should spend more time looking at I like the fact that |
|
About use case 4 above, the case of a One possible solution is simply to tell the programmer to add the following to their (S)CSS: This is a rather large hammer to take to the problem, but given the way |
|
Finally, for the issue of how to handle error messages when there's more than one Spoiler alert: My idea will require creating some new classes, not visible to the end programmer, and likely moving some of the code, specifically the code in @mattbrictson if you have any thoughts about this or my previous comments today, I'm all ears. Or you can wait to see what I come up with. |
|
OK, I will wait to see your solution. In the meantime: I agree that it is important for bootstrap_form to output correct Bootstrap v4 markup, and if we require a little extra from the programmer in edge cases, then that is an acceptable compromise. We don't want to rely on "magic". I'm also on board with documenting the |
|
The new idea I had yesterday turned out to require more |
|
This PR is no longer need since PR #448 has been merged. |
Bootstrap 4 validation errors for groups of check boxes or radio buttons are supposed to be inside the
<div class="form-group">of the last check box or radio button in the group. See: https://getbootstrap.com/docs/4.0/components/forms/#supported-elements.This PR contains some non-trivial refactoring of
check_boxandradio_button. Methods were extracted so that thecollection...helpers could inject the error message when they knew they were working on the last control of the collection. The methods are private, but were left in the file nearcheck_boxandradio_buttonso it's hopefully a little easier to see the changes.This PR also contains an instance variable that cause magic behaviour in
BootstrapForm::Helpers::Bootstrap#append_and_prepend_input, soform_groupdoesn't output the error at the end of the form group that wraps the whole collection.This PR was based off the code in PR #434 and depends on that code.
Fixes #418.