Why errors from custom validation constrain not attached to specific field by to the form?

后端 未结 2 2025
盖世英雄少女心
盖世英雄少女心 2021-01-07 10:11

I have an ArticelPattern class which has $extraPatterns property. This property is an array of ExtraPattern (class) elements.

There is a custom constraint on the cla

相关标签:
2条回答
  • 2021-01-07 10:21

    Belongs to similar problem: use firstName in your entities and forms. Not first_name.

    If your entity (User) has field like firstName, form builder accepts form_field (with underscore) field naming. It saves data correctly and so on. But if you would add some custom constraint to this field, be careful with underscore: don't use it. Use camelCaseFieldNames insted or you'll get errors attached to form, not to field.

    0 讨论(0)
  • 2021-01-07 10:23

    You class constraint is probably being mapped to a form of form type, which has error_bubbling enabled by default. Setting this option to false should do what you're looking for.

    $builder ->add('extraPatterns', 'collection', array(
        // ...
        'options' => array('error_bubbling' => false),
    ));
    
    0 讨论(0)
提交回复
热议问题