mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-19 05:53:51 -04:00
Use email fields for feedback form
Otherwise we can end up collecting invalid email addresses… This required some refactoring to allow our email fields to be optional (but not by default).
This commit is contained in:
@@ -38,6 +38,10 @@ class CsvFileValidator:
|
||||
class ValidGovEmail:
|
||||
|
||||
def __call__(self, form, field):
|
||||
|
||||
if field.data == '':
|
||||
return
|
||||
|
||||
from flask import url_for
|
||||
message = (
|
||||
'Enter a government email address.'
|
||||
@@ -53,10 +57,15 @@ class ValidEmail(Email):
|
||||
super().__init__('Enter a valid email address')
|
||||
|
||||
def __call__(self, form, field):
|
||||
|
||||
if field.data == '':
|
||||
return
|
||||
|
||||
try:
|
||||
validate_email_address(field.data)
|
||||
except InvalidEmailError:
|
||||
raise ValidationError(self.message)
|
||||
|
||||
return super().__call__(form, field)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user