@@ -54,11 +54,9 @@ export default {
54
54
}
55
55
} ,
56
56
data ( ) {
57
- const value = this . stringifyValue ( this . value )
58
-
59
57
return {
60
- localValue : value ,
61
- formattedValue : value
58
+ localValue : this . stringifyValue ( this . value ) ,
59
+ vModelValue : this . value
62
60
}
63
61
} ,
64
62
computed : {
@@ -92,19 +90,20 @@ export default {
92
90
} ,
93
91
watch : {
94
92
value ( newVal ) {
95
- const value = this . stringifyValue ( newVal )
96
- if ( value !== this . localValue ) {
97
- this . localValue = value
98
- this . formattedValue = value
93
+ const stringifyValue = this . stringifyValue ( newVal )
94
+ if ( stringifyValue !== this . localValue && newVal !== this . vModelValue ) {
95
+ this . localValue = stringifyValue
96
+ this . vModelValue = newVal
99
97
}
100
98
}
101
99
} ,
102
100
mounted ( ) {
103
- const value = this . stringifyValue ( this . value )
101
+ const value = this . value
102
+ const stringifyValue = this . stringifyValue ( value )
104
103
/* istanbul ignore next */
105
- if ( value !== this . localValue ) {
106
- this . localValue = value
107
- this . formattedValue = value
104
+ if ( stringifyValue !== this . localValue && value !== this . vModelValue ) {
105
+ this . localValue = stringifyValue
106
+ this . vModelValue = value
108
107
}
109
108
} ,
110
109
methods : {
@@ -113,9 +112,12 @@ export default {
113
112
} ,
114
113
formatValue ( value , evt , force = false ) {
115
114
value = this . stringifyValue ( value )
116
- if ( this . lazy && ! force ) {
117
- return value
115
+ if ( ( ! this . lazyFormatter || force ) && isFunction ( this . formatter ) ) {
116
+ value = this . formatter ( value , evt )
118
117
}
118
+ return value
119
+ } ,
120
+ modifyValue ( value ) {
119
121
// Emulate `.trim` modifier behaviour
120
122
if ( this . trim ) {
121
123
value = value . trim ( )
@@ -125,14 +127,12 @@ export default {
125
127
const number = parseFloat ( value )
126
128
value = isNaN ( number ) ? value : number
127
129
}
128
- if ( ( ! this . lazyFormatter || force ) && isFunction ( this . formatter ) ) {
129
- value = this . formatter ( value , evt )
130
- }
131
130
return value
132
131
} ,
133
132
updateValue ( value , lazy = false ) {
134
- if ( value !== this . formattedValue ) {
135
- this . formattedValue = value
133
+ value = this . modifyValue ( value )
134
+ if ( value !== this . vModelValue ) {
135
+ this . vModelValue = value
136
136
if ( ! lazy ) {
137
137
this . $emit ( 'update' , value )
138
138
}
@@ -154,7 +154,7 @@ export default {
154
154
evt . preventDefault ( )
155
155
return
156
156
}
157
- this . localValue = value
157
+ this . localValue = formattedValue
158
158
this . updateValue ( formattedValue , this . lazy )
159
159
this . $emit ( 'input' , formattedValue )
160
160
} ,
@@ -179,14 +179,17 @@ export default {
179
179
this . $emit ( 'change' , formattedValue )
180
180
} ,
181
181
onBlur ( evt ) {
182
- // Lazy v-model handling
183
- if ( this . lazy || this . lazyFormatter ) {
184
- const value = evt . target . value
185
- const formattedValue = this . formatValue ( value , evt , true )
186
- if ( formattedValue !== false ) {
187
- this . localValue = formattedValue
188
- this . updateValue ( formattedValue )
189
- }
182
+ // Apply the `localValue` on blur to prevent cursor jumps
183
+ // on mobile browsers (e.g. caused by autocomplete)
184
+ const value = evt . target . value
185
+ const formattedValue = this . formatValue ( value , evt , true )
186
+ if ( formattedValue !== false ) {
187
+ // We need to use the modified value here to apply the
188
+ // `.trim` and `.number` modifiers properly
189
+ this . localValue = this . stringifyValue ( this . modifyValue ( formattedValue ) )
190
+ // We pass the formatted value here since the `updateValue` method
191
+ // handles the modifies itself
192
+ this . updateValue ( formattedValue )
190
193
}
191
194
// Emit native blur event
192
195
this . $emit ( 'blur' , evt )
0 commit comments