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

Nested forms drawn field by field lose their full names #211

Open
Danita opened this issue Dec 10, 2019 · 3 comments
Open

Nested forms drawn field by field lose their full names #211

Danita opened this issue Dec 10, 2019 · 3 comments

Comments

@Danita
Copy link

Danita commented Dec 10, 2019

Given the following form definition:

let formFilter = forms.create({
    filter: {
        uname: fields.string({
            label: 'Search by username or email',
        }),
        role: fields.array({
            label: 'By role',
            choices: { m: 'Moderator', g: 'Admin', a: 'Artist' },
            widget: widgets.multipleSelect()
        }),
    }
});

On the template side, if I draw the form using

 !=formFilter.toHTML(bootstrapField)

I get the following query:

{ filter: { uname: 'lala@example.com', role: [ 'm', 'g' ]} }

But if I draw the form fields individually (because of layout needs):

.row
    .col-lg-4
        !=formFilter.fields['filter'].fields['uname'].toHTML(null, bootstrapField)
    .col-lg-3
        !=formFilter.fields['filter'].fields['role'].toHTML(null, bootstrapField)

I get:

{ uname: 'lala@example.com', role: [ 'm', 'g' ]}

I would expect the input names to be derived from the form structure, regardless of how they are rendered. Is there any workaround? Thanks!

@ljharb ljharb closed this as completed Dec 10, 2019
@ljharb ljharb reopened this Dec 10, 2019
@ljharb
Copy link
Collaborator

ljharb commented Dec 10, 2019

whoops, sorry for the mis-close. I'll look into this shortly.

@ljharb ljharb closed this as completed Dec 10, 2019
@ljharb
Copy link
Collaborator

ljharb commented Dec 10, 2019

I can not figure out how this keeps getting closed :-/

@ljharb ljharb reopened this Dec 10, 2019
@ljharb
Copy link
Collaborator

ljharb commented Mar 10, 2020

Sorry for the delay in responding here.

The issue is that, just like a function you extract off an object, once the field is individually rendered, it doesn't have the context to know it's supposed to be nested inside filter.

I could imagine some kind of API on the form object to directly render a specific field's HTML, but it'd require some kind of magic to allow for fielduname, for example, to be represented.

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