Symfony2 Choice field validation not working

后端 未结 1 424
死守一世寂寞
死守一世寂寞 2021-01-23 08:57

I have a form in Symfony 2.7.10 which definition looks like this:



        
相关标签:
1条回答
  • 2021-01-23 09:32

    Ok, I solved it.

    My mistake was to not provide information about mealSchema field in my entity when asking on stackoverflow. If I'd do that then I would realise that the entity field is in fact a smallint.

    My colleague wanted to emulate a MySQL "SET" field type in Doctrine so he used an array as entrypoint values and converted it to bit values in setter method (and the other way around in the getter method).

    That's why none of the choice-related validation rules worked. For now, I've made 2 quick solutions:

    1. Change all fields' names in RecipeType from underscore to camelCase because that is how they are named in our entity. This helped for the error being attached to the form instead of the field.

    2. Used a NotNull validator because the default value of mealSchema was null, not an empty array.

    0 讨论(0)
提交回复
热议问题