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

Allow custom name for Field #223

Open
toptalo opened this issue Dec 11, 2023 · 3 comments · May be fixed by #224
Open

Allow custom name for Field #223

toptalo opened this issue Dec 11, 2023 · 3 comments · May be fixed by #224

Comments

@toptalo
Copy link

toptalo commented Dec 11, 2023

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

@rgs258
Copy link
Contributor

rgs258 commented Dec 19, 2023

@toptalo , I think my branch (and PR) https://github.com/labd/wagtailstreamforms/pull/160/files#diff-951d949d800424b6334469000bf4a47f1841b3fe5b59b25b81d07a779d9a3c11R65 might address your needs. I wonder if that's correct?

@toptalo
Copy link
Author

toptalo commented Dec 19, 2023

@rgs258
You mean that I can override method create_field_name with my own, that will return value of field["value"]["name"]??

@toptalo
Copy link
Author

toptalo commented Dec 19, 2023

Also, have a look into get_data_fields method of wagtailstreamforms/models/form.py

This method must use same logic of getting field name as in wagtailstreamforms/forms.py but for now it only use slug from label
(create_field_name)

That is a point of my Issue - in different places field name makes in different ways

toptalo added a commit to toptalo/wagtailstreamforms that referenced this issue Feb 7, 2024
@toptalo toptalo linked a pull request Feb 7, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants