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

[BUG Select] Use HTMLElement.dataset to get option values in Select doesn't work #341

Open
ppbevilacqua opened this issue Aug 30, 2022 · 4 comments

Comments

@ppbevilacqua
Copy link

Hi everyone, we're updating our project from MUI4 to MUI5, react from v17 to v18 and we need also to update formik-material-ui to formik-mui, according to the documentation.

We're using the Select from 'formik-mui' as formik <Field/> value of component prop, and we're passing objects as options value with <MenuItem/>, but we got an error about this line:

const dataset = (e.target as any).dataset as DOMStringMap;

Problem

When we change the selected option, it sets on form '[object Object]' value. That's because when the dropdown menu closes it calls onChange function to check the value but it gets the current value of the option from HTMLElement.dataset. In our case data-value value of each MenuItem had '[object Object]' value.

image

As a temporary fix, we add a custom onClose that manually sets the field touched:
<Field component={Select} onClose={() => { setFieldTouched(field.name, true, true) }} ... />

@cliedeman
Copy link
Collaborator

Hi @ppbevilacqua
Can you share a code sandbox with the issue?

@ppbevilacqua
Copy link
Author

Hi @cliedeman
that's the link: https://codesandbox.io/s/agitated-rosalind-37142l

I commented onClose prop to simulate the normal case

@schester44
Copy link

schester44 commented Dec 5, 2022

same for numeric values.. #351

they're converted to a string

@ppbevilacqua
Copy link
Author

Hi, any news about 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

No branches or pull requests

3 participants