Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only offer email fields for 'author's email field'? #39

Closed
mjl opened this issue Sep 10, 2024 · 3 comments
Closed

Only offer email fields for 'author's email field'? #39

mjl opened this issue Sep 10, 2024 · 3 comments
Assignees

Comments

@mjl
Copy link
Contributor

mjl commented Sep 10, 2024

How about this? Not sure whether it's in scope for form-designer or people are expected to roll their own solution?

def email_field_choices(form: forms.ModelForm | None, required: bool=True) -> list[tuple[str, str]]:
    if not form:
        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 = [
        ...
                        "author_email_field",
                        forms.ChoiceField(
                            required=False,
                            choices=email_field_choices(form, required=False)
@matthiask
Copy link
Member

Yes! I like it a lot.

@mjl mjl self-assigned this Sep 10, 2024
@mjl
Copy link
Contributor Author

mjl commented Sep 10, 2024

merged #40

@mjl mjl closed this as completed Sep 10, 2024
@matthiask
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants