You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Optional validator is used to short-circuit validation to allow empty field values. This works for single-valued fields but not for multivalued fields. For example, when DateField is used with separate day, month and year controls.
A similar issue exists for InputRequired. Here's a workaround for that:
classMultivalueInputRequired(InputRequired):
""" A validator that ensures input was provided and supports multivalued fields. """def__call__(self, form: BaseForm, field: Field) ->None:
iffield.raw_dataandall(field.raw_data):
returnifself.messageisNone:
message=field.gettext("This field is required.")
else:
message=self.messagefield.errors= []
raiseStopValidation(message)
This is a general design flaw with WTForms. There's many other ways to break Optional/InputRequired/DataRequired.
The best way to clean this up, would be to change the API in 4.0 and expect individual Field classes to deal with the implementation details of what it means for that field to be optional/required.
The
Optional
validator is used to short-circuit validation to allow empty field values. This works for single-valued fields but not for multivalued fields. For example, whenDateField
is used with separate day, month and year controls.Actual Behavior
Expected Behavior
This issue is due to
Optional
only considering the first raw data value.A custom validator can be used to work around this issue:
Although this functionality could easily be accommodated by the library's
Optional
validator.Environment
The text was updated successfully, but these errors were encountered: