I have a content type derived from plone.directives.form.Schema; it has several dozen fields across four fieldsets. I’m trying to create a zope.interface.invariant that looks at fields from two different fieldsets.
From tracing the behaviour, it looks like the invariant is called once for each fieldset, but not for the entire form.
I’m aware I can provide my own handler and perform all the checks I need there, but that feels chunky compared to distinctly defined invariants. While the obvious solution is to move related fields onto the same fieldset, the current setup reflects a layout that is logical the end user.
Is there an existing hook where I could perform validation on multiple fields across fieldsets?
The answer seems to be no:
z3c.form.group.Group.extractDatacallsz3c.form.form.BaseForm.extractDataonce for each group/fieldset, and this call already includes invariant validation.Instead of registering your own handler, you could also overwrite extractData:
Please note that this class derives from dexterity.EditForm, which includes Dexterity’s default handlers, instead of form.SchemaForm.
WidgetActionExecutionErrordoes not work reliably, though. For some fields, it produces a ‘KeyError’.