Skip to content
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

Pull #1188 breaks nested collections. #1497

Closed
blauwers opened this issue Jul 1, 2011 · 1 comment · Fixed by #1724
Closed

Pull #1188 breaks nested collections. #1497

blauwers opened this issue Jul 1, 2011 · 1 comment · Fixed by #1724

Comments

@blauwers
Copy link

blauwers commented Jul 1, 2011

The script wrapper for prototypes from Pull#1188 creates problems for nested collections.

It will put a <script></script> within a <script></script> causing the closing tag of the second embedded prototype to close the first prototype.

See below for some POC code that replicates the issue:

Using RC3

Controller

namespace Acme\BugBundle\Controller;

use
    Symfony\Bundle\FrameworkBundle\Controller\Controller,
    Sensio\Bundle\FrameworkExtraBundle\Configuration as Extra
    ;

use
    Acme\BugBundle\Form\Type\Level1Type;


class DefaultController extends Controller
{

    /**
     * @Extra\Template()
     */
    public function indexAction()
    {
        $form = $this->get('form.factory')->create(new Level1Type());

        return array(
            'form' => $form->createView(), );
    }
}

Template

{{ form_widget(form) }}
<input type="submit" value="submit" />

Level1Type

namespace Acme\BugBundle\Form\Type;

use
    Symfony\Component\Form\AbstractType,
    Symfony\Component\Form\FormBuilder
    ;

class Level1Type extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder
            ->add('startlevel1', 'text')
            ->add('level2', 'collection', array(
                'type' => new Level2Type(),
                'allow_add' => true, ))
            ->add('endlevel1', 'text')
            ;
    }
}

Level2Type

namespace Acme\BugBundle\Form\Type;

use
    Symfony\Component\Form\AbstractType,
    Symfony\Component\Form\FormBuilder
    ;

class Level2Type extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder
            ->add('startlevel2', 'text')
            ->add('level3', 'collection', array(
                'type' => new Level3Type(),
                'allow_add' => true, ))
            ->add('endlevel2', 'text')
            ;
    }
}

Level3Type

namespace Acme\BugBundle\Form\Type;

use
    Symfony\Component\Form\AbstractType,
    Symfony\Component\Form\FormBuilder
    ;

class Level3Type extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder
            ->add('startlevel3', 'text')
            ;
    }           
} 

generated markup

<div id="level1"><input type="hidden" id="level1__token" name="level1[_token]" value="bad35568f69514b59265a4ff15b04548f6168658" /><div><label for="level1_startlevel1">Startlevel1</label><input type="text" id="level1_startlevel1" name="level1[startlevel1]" required="required" value="" /></div><div><label >Level2</label><div id="level1_level2"><script type="text/html" id="level1_level2_prototype"><div><label >$$name$$</label><div id="level1_level2_$$name$$"><div><label for="level1_level2_$$name$$_startlevel2">Startlevel2</label><input type="text" id="level1_level2_$$name$$_startlevel2" name="level1[level2][$$name$$][startlevel2]" required="required" value="" /></div><div><label >Level3</label><div id="level1_level2_$$name$$_level3"><script type="text/html" id="level1_level2_$$name$$_level3_prototype"><div><label >$$name$$</label><div id="level1_level2_$$name$$_level3_$$name$$"><div><label for="level1_level2_$$name$$_level3_$$name$$_startlevel3">Startlevel3</label><input type="text" id="level1_level2_$$name$$_level3_$$name$$_startlevel3" name="level1[level2][$$name$$][level3][$$name$$][startlevel3]" required="required" value="" /></div></div></div></script></div></div><div><label for="level1_level2_$$name$$_endlevel2">Endlevel2</label><input type="text" id="level1_level2_$$name$$_endlevel2" name="level1[level2][$$name$$][endlevel2]" required="required" value="" /></div></div></div></script></div></div><div><label for="level1_endlevel1">Endlevel1</label><input type="text" id="level1_endlevel1" name="level1[endlevel1]" required="required" value="" /></div></div>
<input type="submit" value="submit" />
@vicb
Copy link
Contributor

vicb commented Jul 2, 2011

I have opened a PR as a base for discussion:
#1500

@fabpot fabpot closed this as completed in f29da2f Jul 22, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants