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

Solution to Select for any type, not just Strings #33

Open
Herteby opened this issue Oct 24, 2019 · 2 comments
Open

Solution to Select for any type, not just Strings #33

Herteby opened this issue Oct 24, 2019 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers
Milestone

Comments

@Herteby
Copy link

Herteby commented Oct 24, 2019

For a long time I thought this was impossible to do without writing toString/fromString functions for your custom types, but I just realized that you can make it work by instead using the list index of the options as the "value", and then in the onChange decoder use that index to retrieve the item from the passed in options list.

Here's a demo: https://ellie-app.com/7253Q8THR2xa1

@russelldavies
Copy link
Contributor

Good solution, thanks for posting. This would require a change to the field type from Field values to Field a values which requires lots of changes all over the place but should be doable.

@hecrj
Copy link
Owner

hecrj commented Oct 29, 2019

Thanks for sharing, @Herteby!

We may be able to leverage this without an additional type variable by changing the SelectField underlying value from String to Int, finding the index of the selected value in selectField, and turning the update function a -> values -> values into Int -> values -> values with the provided list of options.

@hecrj hecrj added enhancement New feature or request good first issue Good for newcomers labels Oct 29, 2019
@hecrj hecrj added this to the 9.0.0 milestone Oct 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants