Documentation » Admin

4. Templates »

« 2. Translation

3. Inline Validation

The inline validation code is now part of the SonataCoreBundle. You can refer to the related documentation for more information.

The above examples show how the integration has been done with the SonataAdminBundle. For completeness, it’s worth remembering that the Admin class itself contains an empty validate method. This is automatically called, so you can override it in your own admin class:

// add this to your existing use statements
use Sonata\CoreBundle\Validator\ErrorElement;

class MyAdmin extends AbstractAdmin
    // add this method
    public function validate(ErrorElement $errorElement, $object)
                ->assertLength(['max' => 32])

3.1. Troubleshooting

Make sure your validator method is being called. If in doubt, try throwing an exception:

public function validate(ErrorElement $errorElement, $object)
    throw new \Exception(__METHOD__);

There should not be any validation_groups defined for the form. If you have code like the example below in your Admin class, remove the ‘validation_groups’ entry, the whole $formOptions property or set validation_groups to an empty array:

protected $formOptions = [
    'validation_groups' => []

Found a typo? Something is wrong in this documentation? Just fork and edit it!