From 9e63098972c3ca46f3d331d33a7db8f106a50a57 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 30 Nov 2017 10:48:37 -0500 Subject: [PATCH] fix: should not update in-focus input value with lazy modifier fix #7153 --- .../web/runtime/modules/dom-props.js | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/platforms/web/runtime/modules/dom-props.js b/src/platforms/web/runtime/modules/dom-props.js index c6ba3d0e924..f3888aed066 100644 --- a/src/platforms/web/runtime/modules/dom-props.js +++ b/src/platforms/web/runtime/modules/dom-props.js @@ -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 @@ -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 }