Skip to content

docs(api): note that setValue does not accept objects on <select> - #2819

Merged
cexbrayat merged 2 commits into
vuejs:mainfrom
mvanhorn:osc/2627-setvalue-object-select-docs
Apr 21, 2026
Merged

cexbrayat merged 2 commits into
vuejs:mainfrom
mvanhorn:osc/2627-setvalue-object-select-docs

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Closes #2627

Summary

setValue on a <select> silently does nothing when v-model is bound to an object, because setValue sets the element's value property (always a string) and then fires change — the string never matches any <option>'s value, so v-model never updates.

The maintainer pointed this out on the issue and offered two fixes: (1) document it, (2) teach setValue to match object-typed options the way Vue core does in vModelSelect. This PR does (1) — adds a warning block to the setValue docs that both states the limitation and gives the selectedIndex + 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 existing await warning at the end of the setValue section.

Testing

  • Only a docs page is touched; no code, tests, or types change.
  • The snippet inside the warning matches the workaround the maintainer validated in the issue thread.

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
@netlify

netlify Bot commented Apr 17, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for vue-test-utils-docs ready!

Name Link
🔨 Latest commit f74f9cc
🔍 Latest deploy log https://app.netlify.com/projects/vue-test-utils-docs/deploys/69e7b95072a1a70008e41a58
😎 Deploy Preview https://deploy-preview-2819--vue-test-utils-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@cexbrayat cexbrayat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Thanks @cexbrayat - ported the warning into both language files in f74f9cc:

  • docs/fr/api/index.md: Valeurs objets sur <select> with the same selectedIndex + trigger('change') workaround, placed right after the existing await warning.
  • docs/zh/api/index.md: <select> 上的对象值 with the same structure, matching the style of the 在调用 setValue 时 warning above it.

Code snippet is identical across all three languages. English docs unchanged.

@cexbrayat
cexbrayat merged commit 4b86b3c into vuejs:main Apr 21, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: setValue on select with an object

2 participants