-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Render form errors at the correct position in Bootstrap 4 horizontal layout #27892
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
Conversation
Just updated the tests. Also the test about the form in the label doesn't make sense in the horizontal form anymore. As the test is inherited from the base test class however, I need to overwrite the method. Didn't want to us |
@Nyholm as you added this in #24435 or at least proposed it, I would ask how we should fix the rendering issues? Is just the ordering of wdyt? |
An alternative would be to just add another block {% block form_row -%}
{%- if expanded is defined and expanded -%}
{{ block('fieldset_form_row') }}
{%- else -%}
{%- set widget_attr = {} -%}
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- endif -%}
<div class="form-group row{% if (not compound or force_error|default(false)) and not valid %} is-invalid{% endif %}">
{{- form_label(form) -}}
<div class="{{ block('form_group_class') }}">
{{- form_widget(form, widget_attr) -}}
{%- block form_widget_errors "" -%} {# <-- here! #}
{{- form_help(form) -}}
</div>
{##}</div>
{%- endif -%}
{%- endblock form_row %} So that a user can just do this in his/her own theme: {% extends "bootstrap_4_horizontal_layout.html.twig" %}
{# hide label errors and display them in the widget #}
{%- block form_label_errors "" -%}
{%- block form_widget_errors -%}
{{- form_errors(form) -}}
{%- endblock -%} (or we combine both solutions and add the block above the |
Travis failure is the issue, that 7.1 and 7.2 pull in a more recent version of the twig bridge, which doesn't have this change. This needs to be merged up, then this is automatically fixed. |
@apfelbox For the Status: Needs work |
@xabbuh okay, so what do I need to do here? I am not sure on where I should bump the dependencies. |
Looks like you can apply the same changes to |
|
||
public function testErrorWithNoLabel() | ||
{ | ||
// This test apply to the horizontal form, as here the errors are rendered inside the widget |
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.
applies
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.
"apply" was correct, but should be "doesn't apply" 😄
Will push the change after I see whether the version bumps fix the test failures.
Tests still fail though and I have now idea why. As I am not familiar with how the tests work here I am not quite sure whether the test script is able to automatically install my changed dependencies. Any help appreciated, I didn't do a cross-component PR before. 😅 |
/following-sibling::div[ | ||
./input[@id="name"] | ||
/following-sibling::span[@class="alert alert-danger d-block"] | ||
[./span[@class="mb-0 d-block"] |
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.
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.
So in fact that's now not a dependency problem of different components anymore, but just a conflict with another PR's changes. :)
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.
Oh lol 🤦♀️ I just pushed the changes
Travis failure is unrelated as some compilation crashed. Can I restart the travis build? |
@@ -14,6 +14,8 @@ | |||
{%- endif -%} | |||
{%- endblock form_label %} | |||
|
|||
{%- block form_label_errors "" -%} |
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.
Do we use the short block syntax anywhere else? Otherwise I suggest to not introduce that here. But 👍 from me for the changes here.
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.
Nice catch. I only found one usage in some Tests for the short syntax, but several usages of the explicit syntax in some templates.
So I changed it to the longer version.
wasn't this rendered in the label for accessibility reasons ? |
Fix tests for bootstrap 4 horizontal layout
@stof yep, I linked that above. That's why I would like to wait for the feedback from @Nyholm, because he made these changes and I don't want to introduce a regression here. |
@Nyholm Do you have time to review this one? Would be great. Thanks. |
(rebase needed) |
I'll review this PR this week. Sorry for the delay. |
According to: http://blog.ricardofilipe.com/post/aria-describedby It is possible. But I am not an expert 😛 |
Any progress on this one? |
Hey. Sorry for the delay. I've finally had a sit down with an accessibility expert. She said that it is always recommended to have the error message inside the label. A solution here would be to put the I tried to argue for a different solution. The second best was to use Could you see if you can update this PR to be more accessible? Now when I know the rules it is easier for me to review this PR. |
@Nyholm it seems that horizontal layout is still broken (I stumbled upon this one myself). IMHO maybe we should make it compatible with bootstrap first and then apply some sort of recommendation in the docs informing about this. For me, accessibility provided by bootstrap is very good. |
@fabpot as @Nyholm noted, I could implement the This is a compromise, that should work for both sides, I guess. I would implement it in a way, that you can override this behaviour by just overwriting two blocks. This is like my suggestion in #27892 (comment) so that you have two blocks with possible positions of the error label, and by default one is empty and the other one is filled (but you could change it by extending the template and reversing the positions). |
Thank you for this PR. I like that you addressed the issue but we also need to consider accessibility. I suggest closing this PR and solve it like described here: #28086 (comment) I would be more than happy to review a new PR form you. #eu-fossa |
In the horizontal form layout for Bootstrap 4, the errors render at a weird position. This PR intends to fix it. Not sure about ordering the form error messages and the help block in 4.1, that needs to be decided by the person, that merges this fix upwards. 🙃
Before
After
Edit please note, that the text is in the form label container and wraps pretty early. My example screenshots don't show that too clearly, so here is another one.
vs.