Skip to content

Commit ab5e3b8

Browse files
author
Martin J. Laubach
committed
Send email action: Offer dropdown of email fields present instead of free text input
1 parent d00ec8b commit ab5e3b8

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

form_designer/models.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ def validate_comma_separated_emails(value):
5151
for v in value.split(","):
5252
validate_email(v.strip())
5353

54+
def email_field_choices(form: forms.ModelForm | None, required: bool=True) -> list[tuple[str, str]]:
55+
if not form:
56+
return []
57+
email_fields = form.instance.fields.filter(type='email')
58+
choices = [] if required else [('', '--')]
59+
choices.extend([(_.name, _.title) for _ in email_fields])
60+
return choices
5461

5562
class Form(models.Model):
5663
CONFIG_OPTIONS = [
@@ -86,13 +93,13 @@ class Form(models.Model):
8693
),
8794
(
8895
"author_email_field",
89-
forms.CharField(
96+
forms.ChoiceField(
9097
label=capfirst(_("author's email field")),
9198
help_text=_(
9299
"The author of the submission will be added to the Cc: if this is set to an existing form field below."
93100
),
94101
required=False,
95-
widget=widgets.AdminTextInputWidget,
102+
choices=email_field_choices(form, required=False),
96103
),
97104
),
98105
],

0 commit comments

Comments
 (0)