我有一個z3c.form,在執行表單操作之前無法知道一些錯誤。我想在字段上顯示這些錯誤,而不是在全局表單狀態消息中顯示。任何可以構造並向Form.update()中的小部件注入錯誤?在z3c.form表單中注入字段錯誤表單操作處理程序
例子:
@z3c.form.button.buttonAndHandler(_('Make Report'), name='report')
def report(self, action):
data, errors = self.extractData()
if errors:
self.status = "Please correct errors"
return
# Create sample item which we can consume in the page template
try:
self.output = make_report(self.context, self.request, data, filters=filters)
except zope.interface.Invalid as e:
self.status = e.message
self.errors = True
# How to target the error message to a particular field here
return
self.status = _(u"Report complete")
這基本上和我的代碼做同樣的事情,但硬代碼'WidgetInputError()',而不是查找適配器。這可能很好。 –