Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Report a bug in bootstrap_4_horizontal_layout.html.twig #34008

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
nimasdj opened this issue Oct 17, 2019 · 6 comments
Closed

Report a bug in bootstrap_4_horizontal_layout.html.twig #34008

nimasdj opened this issue Oct 17, 2019 · 6 comments

Comments

@nimasdj
Copy link

nimasdj commented Oct 17, 2019

I have this in template

    <div class="col">
      {{ form_row(form.privacyRead, {'required': false}) }}
    </div>

and this in controller

    ->add('privacyRead', CheckboxType::class, ['constraints' => [new Assert\IsTrue(['message' => 'privacy.notchecked'])],
     ]) 

But I get the error printed twice as here is the output html:


    <div class="col">
      <div class="form-group row"><div class="col-sm-2"></div><div class="col-sm-10"><div class="form-check">        <input type="checkbox"             id="form_privacyRead" name="form[privacyRead]" class="form-check-input is-invalid" value="1" />
        <label class="form-check-label" for="form_privacyRead">I agree Privacy Policy<span class="invalid-feedback d-block"><span class="d-block">
                    <span class="form-error-icon badge badge-danger text-uppercase">Error</span> <span class="form-error-message">privacy.notchecked</span>
                </span></span></label></div><span class="invalid-feedback d-block"><span class="d-block">
                    <span class="form-error-icon badge badge-danger text-uppercase">Error</span> <span class="form-error-message">privacy.notchecked</span>
                </span></span></div></div>
    </div>

It seems something is wrong in bootstrap_4_horizontal_layout.html.twig template.
In source code:

{% block checkbox_row -%}
    <div class="form-group row">{#--#}
        <div class="{{ block('form_label_class') }}"></div>{#--#}
        <div class="{{ block('form_group_class') }}">
            {{- form_widget(form) -}}
            {{- form_help(form) -}}
            {{- form_errors(form) -}}
        </div>{#--#}
    </div>
{%- endblock checkbox_row %}

{{form_errors(form)}} should be removed. No need to this. It still prints error without it. This one causes in duplicate error printing.

@xabbuh
Copy link
Member

xabbuh commented Oct 17, 2019

Can you please create a small example application that allows to reproduce your issue?

@nimasdj
Copy link
Author

nimasdj commented Oct 17, 2019

If you create a single checkbox (e.g. I agree privacy policy) and set it to non-required in template,

{{ form_row(form.privacyRead, {'required': false}) }}

and set a validator for it with IsTrue() constraint,

->add('privacyRead', CheckboxType::class, ['constraints' => [new Assert\IsTrue(['message' => 'privacy.notchecked'])],
     ])

You will see how odd it looks like! As I said {{- form_errors(form) -}} must be removed from bootstrap_4_horizontal_layout.html.twig, to avoid duplicate error message printing for it. I did not check other templates.

@abdellatif05
Copy link

abdellatif05 commented Oct 17, 2019

Symfony version(s) affected: master branch

Description
Validation error shown twice for CheckboxType when applying bootstrap_4_horizontal_layout.html.twig theme to forms

How to reproduce
This is a bug reproducer: https://github.com/abdellatif05/bug-symfony-bootstrap4-horizontal-layout

  1. clone the project
  2. install dependencies
  3. run the project
  4. go to http://localhost:8000/
  5. then click on submit button
  6. the same error will be shown twice for CheckboxType

Additional context
A screenshot after submit the form:

Screen Shot 2019-10-18 at 00 14 10

@nimasdj
Copy link
Author

nimasdj commented Oct 18, 2019

Thanks for creating testcase. I think I found another bug that if you add 'Error' in your translator catalog, the 'ERROR' label is not translated, the same about csrf error message. Do these work for you?
@abdellatif05

@abdellatif05
Copy link

@nimasdj , sorry for the late response, translation works well for me :)

@nicolas-grekas
Copy link
Member

Thank you @abdellatif05 for the reproducer it helped a lot!

nicolas-grekas added a commit that referenced this issue Oct 22, 2019
…bbuh)

This PR was merged into the 3.4 branch.

Discussion
----------

[TwigBridge] do not render errors for checkboxes twice

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #34008
| License       | MIT
| Doc PR        |

Commits
-------

9eddea9 do not render errors for checkboxes twice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants