Skip to content

Class Valid Constraint can't be used on a Form Type #10495

@carlwitt

Description

@carlwitt

I tried to ensure the validity of an embedded object via a form type by adding a valid constraint.

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder->add('publication', new PublicationType(), array(
        'constraints' => array(new \Symfony\Component\Validator\Constraints\Valid())
    ));
}

The problem is that the ConstraintValidatorFactory can't check the constraint on form submission because it tries to instantiate a ValidValidator which doesn't exist.

I'm not sure whether a ValidValidator class is nonsense(1) (as far as I see, the *Validator classes are responsible for the actual validation) but it would be nice to be able to define the valid validation rule in that context, too.

(1) I thought about writing one, but I'm not sure whether there's a single source to retrieve the constraints from. As far as I see, there's at least the validation.yml, annotations in the classes and maybe even constraints defined in the form types.

array (size=4)
  'type' => int 1
  'message' => string 'Class 'Symfony\Component\Validator\Constraints\ValidValidator' not found' (length=72)
  'file' => string '/Users/macbookdata/NetBeansProjects/DTAMetadata/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Validator/ConstraintValidatorFactory.php' (length=146)
  'line' => int 71

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