Symfony2 : Radio buttons in a collection

前端 未结 4 623
说谎
说谎 2021-02-07 13:39

In my application, I created a form using the collection field type :

$builder->add(\'tags\', \'collection\', array(
   \'type\' => new TagTyp         


        
4条回答
  •  -上瘾入骨i
    2021-02-07 14:37

    This is not the right solution, but since you are using jQuery to add/remove...

    TagType

    ->add('main', 'radio', [
        'attr' => [
            'class' => 'toggle'
            ],
         'required' => false
        ])
    

    jQuery

    div.on('change', 'input.toggle', function() {
    
        div
        .find('input.toggle')
        .not(this)
        .removeAttr('checked');
    });
    

    http://jsfiddle.net/coma/CnvMk/

    And use a callback constraint to ensure that there is only one main tag.

提交回复
热议问题