简单检查表单域在 Twig 模板中是否有错误 [英] Simple check if form field has errors in Twig template
本文介绍了简单检查表单域在 Twig 模板中是否有错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Twig 模板中,我检查一个字段是否有这样的错误:
In Twig template I check if a field has an error like this:
{% if form.points.get('errors') is not empty %}
有没有类似的方法:
{% if form.points.hasErrors() %}
简单点?差别不大,但如果我不能做得更容易,为什么不呢.
to do it simpler? It's not a big difference, but if I can't do it easier why not.
推荐答案
该方法不存在.我通常做 {% if form.points.vars.errors|length %}
.
That method does not exist. I typically do {% if form.points.vars.errors|length %}
.
这篇关于简单检查表单域在 Twig 模板中是否有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文