10000 form can't map violation to corresponding form field automatically · Issue #15342 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
form can't map violation to corresponding form field automatically #15342
Closed
@videni

Description

@videni

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0