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
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 */
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With