Symfony2 Choice field validation not working

和自甴很熟 提交于 2019-12-02 04:08:55

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!