Symfony2, validation on getters, show error on form

别说谁变了你拦得住时间么 提交于 2019-12-11 14:01:33

问题


I have a problem with errors using Symfony2 FormComponent.

I've validation for getters in bundle:

getters:
    someGetter:
        - MyOwnValidator: { message: "Fail"}

After that, I want to validate form and show errors:

{{form_errors(form)}}

returns to me bunch of errors (including error for someGetter), but

{{form_errors(form.someGetter)}}

doesn't return anything.

Any ideas?

UPDATE

I've found the solution. Field, for which I implemented validation (someGetter) is a collection type without 'error_bubbling' => 'false' option.

When I added error_bubbling, everything works fine.


回答1:


Other options to have the getters error is with http://symfony.com/doc/current/reference/forms/types/entity.html#error-mapping and http://symfony.com/doc/current/reference/forms/types/entity.html#error-bubbling




回答2:


I've found the solution. Field, for which I implemented validation (someGetter) is a collection type without 'error_bubbling' => 'false' option.

When I added error_bubbling, everything works fine.


Answer extracted from updated question.



来源:https://stackoverflow.com/questions/14719970/symfony2-validation-on-getters-show-error-on-form

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