Skip to content

Conversation

guilhermeblanco
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
License MIT

There is a very weird issue not tracked as part of Symfony 2.4. When creating a form and consuming it using TwigEngine, for the given piece of twig template:

{{ form(my_form, {
    'method': 'POST',
    'action': '/process',
        'attr': {
            'data-name': 'test',
            'class': 'form'
        }
}) }}

It does generate this HTML:

<form name="contact" method="post" action="/process" data-name="test" class="form">
    <div id="contact" data-name="test" class="form">
        <div>
            <label for="contact_email" class="required">Email</label>
            <input type="email" id="contact_email" name="contact[email]" required="required" />
        </div>
        <!-- ... -->
    </div>
</form>

As you may see, it duplicates the attributes of form inside of a div which is the direct child of the form start.
Tracking down the issue, form calls form_start, which renders the form tag. After that, it calls form_widget which makes an initial decision of calling form_widget_compound, creating the div tag with all form attributes.
This patch proposes a fix to not create this initial div tag if form has no parent (root element), properly addressing the issue of duplicated classes (and other items).

This issue affects master and 2.4 from what I've seen.

@fabpot
Copy link
Member

fabpot commented Feb 20, 2014

That change breaks the tests: https://travis-ci.org/symfony/symfony/jobs/19234421

@guilhermeblanco
Copy link
Contributor Author

@fabpot will fix them and ping you back once done.

@webmozart
Copy link
Contributor

see #7709 for the issue description and some discussion

@guilhermeblanco
Copy link
Contributor Author

@webmozart I'd like to understand your decisions around this before working on a final solution.
Right now the only solution I have is to extend the default form theme to get my project going, which doesn't seem like a nice decision to me.
It may be like a trivial thing to do from Symfony's standpoint, but trivial projects are getting a big hit by having default form theme just unusable, forcing everyone to always extend it, not only for custom needs, but also for a simple class definition on a form this became required.

I'll provide comments about the approaches on the other ticket, but I'm more than happy to provide a patch with desired approach. =)

@fabpot
Copy link
Member

fabpot commented Feb 27, 2014

Closing this PR for now as it cannot be merged as is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants