TL; DR AnyOf validation does not support Select Multiple Field. You need to use custom validation.
Looking at the implementation of AnyOf validation, it does not support SelectMultipleField. In the case of SelectMultipleField, field.data is passed as list type, so line 562 always returns True.
https://github.com/wtforms/wtforms/blob/23f730a9cfca478f01fda2b38fde17ad56e9a83d/src/wtforms/validators.py#L562
You can create a validation for Select Multiple Field like this.
def anyof_for_multiple_field(values):
  message = 'Invalid value, must be one of: {0}.'.format( ','.join(values) )
  def _validate(form, field):
    error = False
    for value in field.data:
      if value not in values:
        error = True
    if error:
      raise ValidationError(message)
  return _validate
        Recommended Posts