I have a form with many fields and validation groups, these fields also contain some data converters.
I need to partially close the verification form ( Groups based on submitted data ):
use AppBundle\Entity\Client; use Symfony\Component\Form\FormInterface; use Symfony\Component\OptionsResolver\OptionsResolver; // ... public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'validation_groups' => function (FormInterface $form) { $data = $form->getData(); if (Client::TYPE_PERSON == $data->getType()) { return array('person'); } return array('company'); }, )); }
When you do this, the form will still carry out integrity checks ( Disabling verification ) and verification errors coming from the transformers that they throw out ( Creating a transformer ).
Use the POST_SUBMIT event and do not call the ValidationListener ( Suppression of form confirmation ):
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvent; public function buildForm(FormBuilderInterface $builder, array $options) { $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) { $event->stopPropagation(); }, 900);
This is not a solution for me, as you accidentally disable something more than just form validation.
Question: How to disable one transformer check error "dynamically"?
Example:
I have a RepeatedType form RepeatedType that belongs to the person verification group and contains a transformer of the form ( RepeatedType ), this transformer throws an exception if the values ββin the array do not match ( ValueToDuplicatesTransformer ).
Thus, even if the verification group is company , the form shows errors related to the RepeatedType field coming from the transformer.
Question here: How to disable ValueToDuplicatesTransformer errors when the validation group is not person ?