Skip to content
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

fix(v-model): keep the same behavior as v-model with undefinedvalue with 2.x #1530

Merged
merged 2 commits into from
Jul 6, 2020

Conversation

underfin
Copy link
Member

@underfin underfin commented Jul 6, 2020

fix #1528

@underfin underfin changed the title fix(v-model): keep v-model with undefined insistent as 2.x fix(v-model): keep the same behavior as v-model with undefinedvalue with 2.x Jul 6, 2020
@@ -85,6 +85,7 @@ export const vModelText: ModelDirective<
return
}
}
if (value === undefined || value === null) value = ''

Choose a reason for hiding this comment

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

Literally assigning NULL to native input value should has same effect. Probably checks value === null and value !== null is not required.

Check out example:

  1. Open: https://codesandbox.io/s/native-input-value-nwjoz?file=/index.js
  2. See console logs

@@ -47,7 +47,7 @@ export const vModelText: ModelDirective<
HTMLInputElement | HTMLTextAreaElement
> = {
beforeMount(el, { value, modifiers: { lazy, trim, number } }, vnode) {
el.value = value
if (value !== undefined && value !== null) el.value = value
Copy link
Member

Choose a reason for hiding this comment

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

you should also be able to do

Suggested change
if (value !== undefined && value !== null) el.value = value
if (value != null) el.value = value

@@ -85,6 +85,7 @@ export const vModelText: ModelDirective<
return
}
}
if (value === undefined || value === null) value = ''
Copy link
Member

Choose a reason for hiding this comment

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

Same as above:

Suggested change
if (value === undefined || value === null) value = ''
if (value == null) value = ''

@yyx990803 yyx990803 merged commit 425335c into vuejs:master Jul 6, 2020
@underfin underfin deleted the fix-vmodel branch July 7, 2020 01:01
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.

v-model incorrect behavior with 'undefined' value
4 participants