Reputation: 99
I want to set a MUI Selection for a list of objects ([{name: "", id: "" }]).
The selection list should show the name and id of the object and the selected value should only show the name. The most important part is that I want to return the selected object with id and name in the onChange-handler.
I basically already got the solution what I want to have, but I can't get rid of the "You have provided an out-of-range value..." warnings. Is there a way to solve this or should I just ignore/disable this warnings?
A codesandbox-example of the component is found here
Upvotes: 0
Views: 1506
Reputation: 1333
This is happening because you set a value on the MenuItem to a full object, while you pass a value into Select to be just a string. Change your MenuItem to this:
<MenuItem key={el.id} value={el.id}>
and the Select to this:
<Select
value={entityForm.entity.id}
And you will need to update your handle form code as well, but that would deal with that warning.
EDIT updated answer to use id rather than name
Upvotes: 1