Closed
Description
As I know , an unmapped form filed , its value won't be validated,so I have to validate it manuallly, the purpose of step 1 to demonstrate a child form named userContact is not mapped.
#1. unmapped child form
addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$data = $event->getData();
$orderform = $event->getForm();
$contactForm = $this->formFactory->createNamed('userContact',
vmsp_checkout_contact_type', $data, array(
'auto_initialize' => false,
'mapped' => false,
'label'=> false,
'error_bubbling'=>true,
));
$orderform->add($contactForm);
#2. Map error manually:
->addEventListener(FormEvents::POST_SUBMIT, function(FormEvent $event){
$orderForm = $event->getForm();
//validate userContact.
$userContactForm=$orderForm->get('userContact');
$userContact=$userContactForm->get('userContact')->getData();
$violations=$this->validator->validate($userContact);
$vm = new ViolationMapper();
foreach($violations as $violation)
{
$vm->mapViolation($violation,$userContactForm);
}
});
Question
I have set up validation rules for UserContact entity, one of the rule is to ensure that its userName is not empty.
When I submit empty userName, I can see that error in symfony debug tool bar, but that error message doesn't display in a web page, the error message is supposed to be displayed under userName field of child form userConact. so why symfony can't map the error automatically?anyway to do that?