Skip to content

Allow custom name for Field #223

@toptalo

Description

@toptalo

Hello!

I have a custom submission hook that posts form data to external API.
This API has its own field names defined and I need possibility to control form fields names.

For that purpose I have added neme CharBlock to blocks.StructBlock in get_form_block method of BaseField in wagtailstreamforms_fields.py

I do that, because I found class method get_formfield_name() in source code that trys to get field name from block value

After that I have redefine form fields names, save form config and submit my form.

Than on submissions page I have see, that all new submissions displays with None value.

This was happend because in method get_data_fields field name is a slug generated from label, without checking field["value"]["name"] as was done in get_formfield_name method

So I have suggest to modify this method to respect field name value like so:

(field["value"]["name"] or get_slug_from_string(field["value"]["label"])

    def get_data_fields(self):
        """Returns a list of tuples with (field_name, field_label)."""

        data_fields = [("submit_time", _("Submission date"))]
        data_fields += [
            (field["value"]["name"] or get_slug_from_string(field["value"]["label"]), field["value"]["label"])
            for field in self.get_form_fields()
        ]
        if getattr(settings, "WAGTAILSTREAMFORMS_SHOW_FORM_REFERENCE", False):
            data_fields += [("form_reference", _("Form reference"))]
        return data_fields

What dou you think?
I can make PR for that

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions