Open xieranmaya opened 5 years ago
as a workaround you can set a key
on the select
element that changes alongside the selected list
It has nothing to do with the key, add key or keys do not resolve the problem. Acturally the bug is triggered by an internal logic. See the pr I created above. @posva
A workaround is only a temporary fix for the problem for you or anybody to have a solution until a fix is released: The original problem has nothing to deal with keys yet, adding a key
does remove the bug
@posva Maybe im reading the description incorrectly but this sounds like expected behavior. If i change the list of available options, and then change the value to something not in the list of available options, it should be undefined
, right?
It should keep the set value instead of changing it to undefined
This issue is owned by the logic of the code:
https://github.com/vuejs/vue/pull/10615/files
the $selectedValue
variable in line 121 may be an empty array, but the subsequent code read its first element, if the code is in c/c++, that would be an error or index out of bound.
setting it to undefined
is just an accident.
Version
2.6.10
Reproduction link
https://jsfiddle.net/4fyrj95L/
Steps to reproduce
set model binded to select element and the array that iterated the option list at the same time
make sure the new model value do not match any of the new options
the model will be set to
undefined
What is expected?
model value to be set to
1
What is actually happening?
model's value set to
undefined
This bug only appears when model and the options changed at the same and the new model value does not match any option, other situations behaves correctly as far as I tested.