Skip to content

[TwigBridge] render errors as part of the label only #29207

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

Closed
wants to merge 1 commit into from
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
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ col-sm-10
<div class="{{ block('form_label_class') }}"></div>{#--#}
<div class="{{ block('form_group_class') }}">
{{- form_widget(form) -}}
{{- form_errors(form) -}}
{{- form_errors(form, _context|merge({'render_errors': true})) -}}
</div>{#--#}
</div>
{%- endblock checkbox_row %}
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@
{% set label = name|humanize %}
{%- endif -%}
{%- endif -%}
<{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}{% block form_label_errors %}{{- form_errors(form) -}}{% endblock form_label_errors %}</{{ element|default('label') }}>
<{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}{% block form_label_errors %}{{- form_errors(form, _context|merge({'render_errors': true})) -}}{% endblock form_label_errors %}</{{ element|default('label') }}>
{%- else -%}
{%- if errors|length > 0 -%}
<div id="{{ id }}_errors" class="mb-2">
{{- form_errors(form) -}}
{{- form_errors(form, _context|merge({'render_errors': true})) -}}
</div>
{%- endif -%}
{%- endif -%}
Expand Down Expand Up @@ -250,7 +250,7 @@
{{ widget|raw }}
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
{{- label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans({}, translation_domain)) -}}
{{- form_errors(form) -}}
{{- form_errors(form, _context|merge({'render_errors': true})) -}}
</label>
{%- endif -%}
{%- endblock checkbox_radio_label %}
Expand All @@ -270,7 +270,7 @@
{# Errors #}

{% block form_errors -%}
{%- if errors|length > 0 -%}
{%- if render_errors|default(false) and errors|length > 0 -%}
Copy link
Contributor

Choose a reason for hiding this comment

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

im not sure i get it.. this makes form_errors practically a no-op by default right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, and that's also why I am not convinced that we should make the change in core. It might break custom form themes. I rather tend to fix the documentation instead.

Copy link
Contributor

@ro0NL ro0NL Nov 14, 2018

Choose a reason for hiding this comment

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

it could work like form_rest is working maybe; only render errors in form_errors if not already rendered

Copy link
Contributor

Choose a reason for hiding this comment

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

either way, 👍 for better docs: customizing form errors inside the label vs. outside the label.

Copy link
Contributor

Choose a reason for hiding this comment

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

or maybe make the current feature more explicit: form_label_with_errors? so if you start customizing based on core files you'll understand you need to pick form_label+form_errors vs. form_label_with_errors

<span class="{% if form is not rootform %}invalid-feedback{% else %}alert alert-danger{% endif %} d-block">
{%- for error in errors -%}
<span class="d-block">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
{%- else -%}
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) -%}
<div {{ block('widget_container_attributes') }}>
{{- form_errors(form.date) -}}
{{- form_errors(form.time) -}}
{{- form_errors(form.date, _context|merge({'render_errors': true})) -}}
{{- form_errors(form.time, _context|merge({'render_errors': true})) -}}

<div class="sr-only">
{%- if form.date.year is defined %}{{ form_label(form.date.year) }}{% endif -%}
Expand Down Expand Up @@ -105,7 +105,7 @@
{%- else -%}
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) -%}
<div {{ block('widget_container_attributes') }}>
{{- form_errors(form) -}}
{{- form_errors(form, _context|merge({'render_errors': true})) -}}
<div class="table-responsive">
<table class="table {{ table_class|default('table-bordered table-condensed table-striped') }}" role="presentation">
<thead>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ protected function renderLabel(FormView $view, $label = null, array $vars = arra

protected function renderErrors(FormView $view)
{
return (string) $this->renderer->searchAndRenderBlock($view, 'errors');
return (string) $this->renderer->searchAndRenderBlock($view, 'errors', array(
'render_errors' => true,
));
}

protected function renderWidget(FormView $view, array $vars = array())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ protected function renderLabel(FormView $view, $label = null, array $vars = arra

protected function renderErrors(FormView $view)
{
return (string) $this->renderer->searchAndRenderBlock($view, 'errors');
return (string) $this->renderer->searchAndRenderBlock($view, 'errors', array(
'render_errors' => true,
));
}

protected function renderWidget(FormView $view, array $vars = array())
Expand Down