Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sonata Admin type_collection & cascade validation

I am having a problem with implementing the one to many relationship in the sonata admin with the following structure.

->add('adhesions', 'sonata_type_collection', array('by_reference' => false,'required' => false), array(
    'edit' => 'inline',
    'inline' => 'table',
    'sortable'  => 'position',))

With this option : 'edit' => 'inline', i lost default validation defined in AdhesionAdmin like 'required' => true.

So, is there a setting to specify somewhere ? I tried to add 'cascade_validation' => true in settings of the sonata_type_collection but it has not changed.

Another question: can I use popup edit form with the sonata_type_collection ? ('edit' => 'standard')

Any pointers and help is highly appreciated. Thank you

like image 525
java Avatar asked Mar 19 '13 10:03

java


2 Answers

You have to enable cascade_validation. You can do it this way:

  class UserAdmin extends SonataUserAdmin  
  {    
     protected $formOptions = array(
        'cascade_validation' => true        
     );

     /* Rest of your admin class code */


  }
like image 193
jbbrunsveld Avatar answered Nov 13 '22 04:11

jbbrunsveld


Just use Valid constraint on your entity property instead:

/**
 * @var Object[]
 *
 * @ORM\OneToMany(targetEntity="AppBundle\Entity\Object", mappedBy="myEntity")
 * @Assert\Valid
 */
private $objects;

http://symfony.com/doc/current/reference/forms/types/collection.html#cascade-validation

like image 9
Soullivaneuh Avatar answered Nov 13 '22 04:11

Soullivaneuh