-
Notifications
You must be signed in to change notification settings - Fork 196
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
Conversation
</div> | ||
``` | ||
|
||
Note: `multiple` attribute is only valid for email input, file input, and select |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep that works 👍
There was a problem hiding this comment.
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:
- Is it correct that the only diff should be in fieldValue. It should probably be
[Text]
instead ofText
? - 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.
There was a problem hiding this comment.
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
Closes #893