Open cdw9 opened 7 years ago
Also the docs indicate I can specify a widget instead of a field. Two of these fields use the same widget, so I tried:
validator.WidgetValidatorDiscriminators(
AlphaNumericValidator, widget=DataGridFieldFactory)
But this did not work either, and there is no error. The validator is not accessed.
Would also like some feedback on this, would be nice to pass multiple fields to the validator..?
I believe you have to use different discriminators to get this working. @cdw9 Is it correct that each of your fields uses the same zope.schema field class? If yes it results in the same discriminator. (Maybe an exception should be raised if this happens but this can be filed as in issue if my analysis is correct here.)
A workaround could be to provide a special interface for each field. Like this: (untested)
class IAvailableAreas(zope.interface.Interface):
pass
class IAvailableIssueTypes(zope.interface.Interface):
pass
class ITracker(zope.interface.Interface):
available_areas = zope.schema.TextLine()
available_issue_types = zope.schema.TextLine()
zope.interface.alsoProvides(ITracker['available_areas'], IAvailableAreas)
zope.interface.alsoProvides(ITracker['available_issue_types'], IAlphaNumValue2)
validator.WidgetValidatorDiscriminators(
AlphaNumericValidator, field=IAvailableAreas)
validator.WidgetValidatorDiscriminators(
AlphaNumericValidator, field=IAvailableIssueTypes)
Does this help?
I've created a validator, but it will only work on one field at a time. Currently I have:
The validator will work on one of the fields, but ignores the other two. I've confirmed the validation works on each separately. How can I use the same validator on multiple fields?