Question

I am using Symfony 2.3.

I have created simple order form using $this->createFormBuilder in my controller. I am validating one Doctrine field with:

/**
 * @Assert\Length(min=3)
 */
protected $name;

However, upon validation fail, I get a duplicated error message near the field:

This value is too short. It should have 3 character or more.|This value is too short. It should have 3 characters or more.

My template for this element is as simple as:

{{ form_errors(form.name) }}
{{ form_label(form.name) }}
{{ form_widget(form.name) }}

Everything else seems to bet working as expected, except for that validation error message being duplicated. As if pluralization would not be working. Anyone has a suggestion on why this would be failing?

EDIT

It seems that SonataAdminBundle is overriding form_errors block. How to remove that override from non-sonata controller?

Was it helpful?

Solution 2

The problem was that I had set this in my config.yml:

# Twig Configuration
twig:
    debug:            %kernel.debug%
    strict_variables: %kernel.debug%

    form:
        resources:
            - 'SonataAdminBundle:Form:silex_form_div_layout.html.twig'
            - 'SonataFormatterBundle:Form:formatter.html.twig'

The silex_form_div_layout.html.twig one overrides form_errors Twig block, and removing it fixes the problem.

OTHER TIPS

Maybe the sonata's template is not in sync with the latest changes from the original template.

Can you create a PR or an issue on github, thanks

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top