Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3925

Sonata AdminType fields are not validated

$
0
0

I have two admins UserAdmin and UserSettingsAdmin. In the UserAdmin I added a AdminType field that embeds UserSettingsAdmin form fields:

// AppBundle\Admin\UserAdmin.php$formMapper  ->add('settings', AdminType::class, ['label' => false  ]);// AppBundle\Admin\UserSettingsAdmin.php$formMapper  ->add('canBookUntil', ChoiceType::class, ['label' => 'Gali rezervuotis iki','choices' => $choices,'placeholder' => 'Darbo dienos pabaigos','empty_data' => null  ]);

Form is displayed correctly. UserAdmin contains UserSettingsAdmin form fields.

I added some assertions to canBookUntil field including validate() callback to test that validation works from parent form:

// AppBundle\Entity\User.php/** * @var UserSettings * @ORM\OneToOne(targetEntity="UserSettings", mappedBy="user", cascade={"persist"}) */public $settings;// AppBundle\Entity\UserSettings.php/** * @var string|null * @ORM\Column(type="string", length=15, nullable=true) * @Assert\NotBlank(message="Pasirinkite laiką.") */private $canBookUntil;// .../** * @Assert\Callback * @param mixed $payload */public function validate(ExecutionContextInterface $context, $payload): void{  $context->buildViolation('Įveskite laiką.')->atPath('canBookUntil')->addViolation();}

Unfortunately, after UserAdmin form submit button click, the form error is not displayed.

Am I missing something?

I tried submitting UserSettingsAdmin form and error appears..


Viewing all articles
Browse latest Browse all 3925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>