Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What the purpose of value-comparator in Vuetify v-select or v-autocomlete

Tags:

vuetify.js

After providing a custom function to value-comparator, I have realized that it's a way to decide which item should appear after selection is made and the dropdown is closed.

Does this property serve any other purpose, i.e., v-model or dim selected item?

like image 444
Samiullah Khan Avatar asked Mar 28 '19 07:03

Samiullah Khan


1 Answers

value-comparator controls which values are currently shown as selected in v-select and v-autocomplete.

By default, it uses a strict comparison:

valueComparator: (a, b) => Math.round(a) === Math.round(b)

It serves a purpose in v-model in that it is used to determine whether the value passed to v-model is being correctly detected as "selected". For example, if the list of items passed to v-select uses integer ids as values, and the data value initially passed to v-model is a string, v-select will show that no value was selected. You can either cast the initial data value to a string, cast item values as strings, or explicitly set the compare function to one using a weak comparison (==).

like image 135
Amade Avatar answered Sep 20 '22 16:09

Amade