Skip to content

Commit 3d9e560

Browse files
authored
Merge pull request #40 from mjl/email-submission-select
Send email action email field
2 parents d00ec8b + 92cabed commit 3d9e560

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

form_designer/models.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
import warnings
24
from functools import partial
35

@@ -51,6 +53,13 @@ def validate_comma_separated_emails(value):
5153
for v in value.split(","):
5254
validate_email(v.strip())
5355

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

5564
class Form(models.Model):
5665
CONFIG_OPTIONS = [
@@ -86,13 +95,13 @@ class Form(models.Model):
8695
),
8796
(
8897
"author_email_field",
89-
forms.CharField(
98+
forms.ChoiceField(
9099
label=capfirst(_("author's email field")),
91100
help_text=_(
92101
"The author of the submission will be added to the Cc: if this is set to an existing form field below."
93102
),
94103
required=False,
95-
widget=widgets.AdminTextInputWidget,
104+
choices=email_field_choices(form, required=False),
96105
),
97106
),
98107
],

0 commit comments

Comments
 (0)