Skip to content

Commit

Permalink
fix: should not update in-focus input value with lazy modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 authored and lovelope committed Feb 1, 2018
1 parent f0001b1 commit 9e63098
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/platforms/web/runtime/modules/dom-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ type acceptValueElm = HTMLInputElement | HTMLSelectElement | HTMLOptionElement;
function shouldUpdateValue (elm: acceptValueElm, checkVal: string): boolean {
return (!elm.composing && (
elm.tagName === 'OPTION' ||
isDirty(elm, checkVal) ||
isInputChanged(elm, checkVal)
isNotInFocusAndDirty(elm, checkVal) ||
isDirtyWithModifiers(elm, checkVal)
))
}

function isDirty (elm: acceptValueElm, checkVal: string): boolean {
function isNotInFocusAndDirty (elm: acceptValueElm, checkVal: string): boolean {
// return true when textbox (.number and .trim) loses focus and its value is
// not equal to the updated value
let notInFocus = true
Expand All @@ -71,14 +71,20 @@ function isDirty (elm: acceptValueElm, checkVal: string): boolean {
return notInFocus && elm.value !== checkVal
}

function isInputChanged (elm: any, newVal: string): boolean {
function isDirtyWithModifiers (elm: any, newVal: string): boolean {
const value = elm.value
const modifiers = elm._vModifiers // injected by v-model runtime
if (isDef(modifiers) && modifiers.number) {
return toNumber(value) !== toNumber(newVal)
}
if (isDef(modifiers) && modifiers.trim) {
return value.trim() !== newVal.trim()
if (isDef(modifiers)) {
if (modifiers.lazy) {
// inputs with lazy should only be updated when not in focus
return false
}
if (modifiers.number) {
return toNumber(value) !== toNumber(newVal)
}
if (modifiers.trim) {
return value.trim() !== newVal.trim()
}
}
return value !== newVal
}
Expand Down

0 comments on commit 9e63098

Please sign in to comment.