Formik with Listbox and default value (codesandbox provided) #1695
Replies: 3 comments
-
I am getting the same issue at this very moment with the latest insiders release too. It seems like the initially selected values bound via I've also tried using other props such as |
Beta Was this translation helpful? Give feedback.
-
Okay, I've done some experimentation and I believe the issue is that the combobox is matching selected items by javascript reference(s) when binding objects as values. I.E. the objects used to populate the available options often are not the same objects "selected" and so do now match. Ideally I think the combobox needs to support a method of checking selected/matched values using a specified property on the objects; not sure they nicest way to deal with this. In my case, to work around this issue, I changed the value binding to map from object to an array of "ids", changed the option values to use a id property rather than the entire object and then changed the onChange to map from an id array to a items array using the items used to populate the combobo box; hope that makes sense. Short version is, binding data in converts to id array, binding out on change converts from ids to items. I've forked and updated your codesandbox to demonstrate how I worked around the issue and gets it working in your scenario. |
Beta Was this translation helpful? Give feedback.
-
In case someone comes across this post as I did, the Listbox component allows you to specify a field to use to identify which value is selected or not : the |
Beta Was this translation helpful? Give feedback.
-
Hi :)
I have this codesandbox that reproduces my problem. When I have values defined by my form (with
Formik
), I'm able to select the value that is already present in my initial value.I'm not sure what am doing wrong here. Any help would be really appreciated
Beta Was this translation helpful? Give feedback.
All reactions