Repository navigation
docs(api): note that setValue does not accept objects on <select> - #2819
Merged
cexbrayat merged 2 commits intoApr 21, 2026
Merged
Conversation
setValue compares the passed value against a <select>'s DOM value, which is always a string. When v-model binds an object, passing the object to setValue silently does nothing because it never matches any <option>'s string value. Users hit this in vuejs#2627 and spend time debugging before learning they should set selectedIndex and trigger a change event instead. Document the gotcha and the workaround in the setValue reference so the next user finds the answer in the docs instead of an issue thread. Closes vuejs#2627
✅ Deploy Preview for vue-test-utils-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
cexbrayat
reviewed
Apr 20, 2026
cexbrayat
left a comment
Member
There was a problem hiding this comment.
LGTM, thanks 👍
Can you add the same note in other languages as well please (using your favorite agent)?
Review from @cexbrayat on vuejs#2819 asked to add the same warning to the other language docs. Ports the `warning Object values on <select>` block into docs/fr/api/index.md and docs/zh/api/index.md, preserving the code snippet verbatim and translating only the prose: - fr: Valeurs objets sur <select> -- selectedIndex + trigger('change') is described as the workaround, matching the existing warning style used by the nearby await block. - zh: <select> 上的对象值 -- same structure, translated to match the existing 在调用 setValue 时 warning immediately above. No English change.
Contributor
Author
|
Thanks @cexbrayat - ported the warning into both language files in f74f9cc:
Code snippet is identical across all three languages. English docs unchanged. |
cexbrayat
approved these changes
Apr 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2627
Summary
setValueon a<select>silently does nothing whenv-modelis bound to an object, becausesetValuesets the element'svalueproperty (always a string) and then fireschange— the string never matches any<option>'s value, sov-modelnever updates.The maintainer pointed this out on the issue and offered two fixes: (1) document it, (2) teach
setValueto match object-typed options the way Vue core does invModelSelect. This PR does (1) — adds a warning block to thesetValuedocs that both states the limitation and gives theselectedIndex + trigger('change')workaround. Implementing option (2) would be a separate PR.Change
Single-file diff in
docs/api/index.md: adds a new::: warning Object values on <select>block next to the existingawaitwarning at the end of thesetValuesection.Testing