Symfony2 - Dynamic form choices - validation remove

前端 未结 5 1046
挽巷
挽巷 2021-01-02 00:28

I have a drop down form element. Initially it starts out empty but it is populated with values via javascript after the user has made some interactions. Thats all working

5条回答
  •  礼貌的吻别
    2021-01-02 01:03

    Update in Validations.yml

    Kindly update the Validation.yml file in the below format : setting the group names in the each field

     
             password:
                - NotBlank: { message: Please enter password ,groups: [Default]}
    Update in Form Type /** * @param OptionsResolverInterface $resolver */ public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'data_class' => 'RegistrationBundle\Entity\sf_members', 'validation_groups' => function(FormInterface $form){
    $data = $form->getData();
    $member_id = $data->getMemberId();

    // Block of code; // starts Here :

    if( condition == 'edit profile') { return array('edit'); } else { return array('Default'); } },

    Update in Entity /** * @var string * * @ORM\Column(name="password", type="text") * @Assert\Regex( * pattern="/(?i)^(?=.[a-zA-Z])(?=.\d).{8,}$/", * match=true, * message="Your password must be at least 8 characters, including at least one number and one letter", * groups={"Default","edit"} * ) */
    private $password;

提交回复
热议问题