Skip to content

Commit

Permalink
Merge pull request #40 from mjl/email-submission-select
Browse files Browse the repository at this point in the history
Send email action email field
  • Loading branch information
mjl authored Sep 10, 2024
2 parents d00ec8b + 92cabed commit 3d9e560
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions form_designer/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

import warnings
from functools import partial

Expand Down Expand Up @@ -51,6 +53,13 @@ def validate_comma_separated_emails(value):
for v in value.split(","):
validate_email(v.strip())

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

class Form(models.Model):
CONFIG_OPTIONS = [
Expand Down Expand Up @@ -86,13 +95,13 @@ class Form(models.Model):
),
(
"author_email_field",
forms.CharField(
forms.ChoiceField(
label=capfirst(_("author's email field")),
help_text=_(
"The author of the submission will be added to the Cc: if this is set to an existing form field below."
),
required=False,
widget=widgets.AdminTextInputWidget,
choices=email_field_choices(form, required=False),
),
),
],
Expand Down

0 comments on commit 3d9e560

Please sign in to comment.