Skip to content

fix(runtime-dom): v-model on checkbox can work with truthy/falsy values (#5775) #5780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

shadowings-zy
Copy link
Contributor

Fix #5775

@netlify
Copy link

netlify bot commented Apr 22, 2022

Deploy Preview for vue-next-template-explorer ready!

Name Link
🔨 Latest commit a776522
🔍 Latest deploy log https://app.netlify.com/sites/vue-next-template-explorer/deploys/626255fedb013300087359ed
😎 Deploy Preview https://deploy-preview-5780--vue-next-template-explorer.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 site settings.

@netlify
Copy link

netlify bot commented Apr 22, 2022

Deploy Preview for vuejs-coverage ready!

Name Link
🔨 Latest commit a776522
🔍 Latest deploy log https://app.netlify.com/sites/vuejs-coverage/deploys/626255fe19c4ee000882a875
😎 Deploy Preview https://deploy-preview-5780--vuejs-coverage.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 site settings.

@netlify
Copy link

netlify bot commented Apr 22, 2022

Deploy Preview for vue-sfc-playground ready!

Name Link
🔨 Latest commit a776522
🔍 Latest deploy log https://app.netlify.com/sites/vue-sfc-playground/deploys/626255fe03a382000945f432
😎 Deploy Preview https://deploy-preview-5780--vue-sfc-playground.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 site settings.

@haoqunjiang haoqunjiang added need guidance The approach/solution in the PR is unclear and requires guidance from maintainer to proceed further. scope: v-model labels May 29, 2024
Comment on lines +153 to +157
if (el._trueValue === undefined && el._falseValue === undefined) {
el.checked = looseEqual(!!value, getCheckboxValue(el, true))
} else {
el.checked = looseEqual(value, getCheckboxValue(el, true))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (el._trueValue === undefined && el._falseValue === undefined) {
el.checked = looseEqual(!!value, getCheckboxValue(el, true))
} else {
el.checked = looseEqual(value, getCheckboxValue(el, true))
}
if ('_trueValue' in el || '_falseValue' in el) {
el.checked = looseEqual(value, getCheckboxValue(el, true))
} else {
el.checked = !!value
}
  1. Using in rather than === undefined would be more consistent with getCheckboxValue, allowing undefined to be used as a value. I've flipped the branches to avoid negating everything.
  2. looseEqual(!!value, getCheckboxValue(el, true)) simplifies down to just !!value if trueValue isn't specified.
  3. On the latest main, el.checked has been replaced with a local variable called checked, but otherwise the logic should be the same.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need guidance The approach/solution in the PR is unclear and requires guidance from maintainer to proceed further. scope: v-model
3 participants