Could someone explain me why the initialisation of a select Input is not possible from an Object ?
initValue1 = ({ name: "Warriors", location: "San Francisco, California" })
viewof favorite1 = Inputs.select(teams, {
label: "Favorite team",
format: (x) => x.name,
value: initValue1
})
See:
https://observablehq.com/d/7b0e463acd4a21dc
1 Like
Your notebook is not public, butâŚ
Try something like
initValue1 = teams[0]
The issue is that your initValue1
is not the same object as teams[0]
; they have the same value but they are not the same object.
Have set the notebook as public.
Nope, it seems not to work.
Works for me.
viewof favorite1 = Inputs.select(teams, {
label: "Favorite team",
format: (x) => x.name,
value: teams[1]
})
You can also use the key option to initialize the selected value if itâs easier.
viewof favorite2 = Inputs.select(new Map(teams.map((t) => [t.name, t])), {
label: "Favorite team",
key: "Warriors"
})
Indeed it works with teams[1]
but not the value itself. That was my question.
viewof favorite1 = Inputs.select(teams, {
label: "Favorite team",
format: (x) => x.name,
value: { name: "Warriors", location: "San Francisco, California" }
})
gives the âLakersâ not the âWarriorsâ
Right, you canât do that because itâs not the same object, as pointed out above.
Ok I understand now.
Thank you very much.