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

Add multiple Attribute To FormField #1004

Closed
wants to merge 2 commits into from
Closed

Add multiple Attribute To FormField #1004

wants to merge 2 commits into from

Conversation

s0kil
Copy link
Collaborator

@s0kil s0kil commented Jul 25, 2021

Closes #893

</div>
```

Note: `multiple` attribute is only valid for email input, file input, and select
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add a note here on how to consume a multi input from the action? I guess it's with paramList, but have not checked it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone creates a column such as email TEXT[] NOT NULL, meaning an list of emails. Then they probably expect to be able to do this:

renderForm :: Person -> Html
renderForm person = formFor person [hsx|
    {(selectField #email emails) { multiple = True }}
    {submitButton}
|]
    where
        emails :: [Text]
        emails = ["[email protected]", "[email protected]", "[email protected]"]

however, there is a compiler error:

Couldn't match type `SelectValue Text' with `[Text]'
        arising from a use of `selectField'

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the selectField function does not account for multiple selections, or a list of emails.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mpscholten any pointer on how to fix this?

Copy link
Collaborator

@amitaibu amitaibu Nov 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems the above error is unrelated to the PR. I've tried with https://ihp.digitallyinduced.com/Guide/form.html#select-inputs-with-integers and seem to get a similar error

I think that the problem is that my field is of type [Int] and currently SelectValue knows only how to work with a single value

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not as easy to fix as it sounds.

Basically we'd need to change the data structure for the select field to support multiple values. Right now most form fields use this big FormField data structure.

We would like need to make a specialized SelectField data structure that is then returned by the selectField function. The SelectField then could have support for a list of values.

Not sure if that's worth the trouble for now.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so the current workaround, I guess, would be to use checkboxes as described in https://ihp.digitallyinduced.com/Guide/controller.html#multiple-params-with-same-name-checkboxes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep that works 👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mpscholten it might be too complex for my current skills, but maybe I could give it a try, for educational fun 😃

Couple of questions I have:

  1. Is it correct that the only diff should be in fieldValue. It should probably be [Text] instead of Text?
  2. If so, would we copy the entire FormField, and change only that property, or should we move it to some instance?

If it's more elaborate than that, maybe someone could write down how the types would look, and I'll try to follow from there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it correct that the only diff should be in fieldValue. It should probably be [Text] instead of Text?

yep that's basically it :) We need to be careful not to break BC with existing forms, that might actually be a bit tricky (e.g. that bug with the duplicate label field name we had recently on master would likely also be triggered here)

Likely the best way is to just get started and then we'll iterate our way there

This pull request was closed.
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 this pull request may close these issues.

Support select field with multiple selections
4 participants