widgetti / ipyvuetify

Jupyter widgets based on vuetify UI components
MIT License
347 stars 59 forks source link

Cannot use different value and text in CombBox #117

Open 12rambau opened 3 years ago

12rambau commented 3 years ago

If I read the documentation of Combobox, The items property can be a list of dict as :

{
  text: string | number | object,
  value: string | number | object,
  disabled: boolean,
  divider: boolean,
  header: string
}

when I use it in a ipyvuetify as such :

climate_regimes = [
    {'text': 'Temperate dry (coef = 0.8)',    'value': 0.80},
    {'text': 'Temperate moist (coef = 0.69)', 'value': 0.69},
    {'text': 'Tropical dry (coef = 0.58)',    'value': 0.58},
    {'text': 'Tropical moist (coef = 0.48)',  'value': 0.48},
    {'text': 'Tropical montane (coef = 0.64)','value': 0.64}
]

tutu = v.ComboBox(items=climate_regimes, v_model=None)

but when I check tutu.v_model after selecting the first option, I get: {'text': 'Temperate dry (coef = 0.8)', 'value': 0.80}instead of the expected 0.8

mariobuikhuizen commented 3 years ago

This is how Vuetify works, ipyvuetify does not change this.

This makes it not very usable with link. We could make a special link version in which you can specify a conversion function.

12rambau commented 3 years ago

Are you sure that it's normal vuetify behaviour ? Because if I do the same in a select :

tutu = v.Select(items=climate_regimes, v_model=None)

then tutu.v_model has the expected 0.8value. Both api component have the same doc regarding the items prop

mariobuikhuizen commented 3 years ago

It's indeed different for Select. I see now it's because of the prop return-object that has a different default.

mariobuikhuizen commented 3 years ago

Is this solved by setting return-object to False on Combobox?

12rambau commented 3 years ago

yes and no.

with :

tutu = v.Combobox(items=climate_regimes, v_model=None, return_object = False)

I effectively get the value field in the tutu.v_model but then what's written in the combobox is not the text field of the dictionary but simply the v_model which is not the behaviour observed with the Select component