@@ -17,6 +17,7 @@ export default {
17
17
el = core . getInputElement ( el )
18
18
const option = el [ CONFIG_KEY ]
19
19
const { config } = option
20
+
20
21
// prefer adding event listener to parent element to avoid Firefox bug which does not
21
22
// execute `useCapture: true` event handlers before non-capturing event handlers
22
23
const handlerOwner = el . parentElement || el
@@ -36,9 +37,12 @@ export default {
36
37
// check decimal key and insert to current element
37
38
// updated cursor position after format the value
38
39
el . onkeydown = ( e ) => {
40
+ const { target } = e
41
+ const regExp = new RegExp ( `${ config . prefix } |${ config . suffix } ` , 'g' )
42
+ let newValue = target . value . replace ( regExp , '' )
39
43
if (
40
44
( [ 110 , 190 ] . includes ( e . keyCode ) || e . key === config . decimal ) &&
41
- el . value . includes ( config . decimal )
45
+ newValue . includes ( config . decimal )
42
46
) {
43
47
e . preventDefault ( )
44
48
} else if ( [ 8 ] . includes ( e . keyCode ) ) {
@@ -72,9 +76,9 @@ export default {
72
76
73
77
updated : ( el , { value, oldValue, modifiers } , vnode ) => {
74
78
el = core . getInputElement ( el )
79
+ const { config } = el [ CONFIG_KEY ]
80
+ el [ CONFIG_KEY ] . config = Object . assign ( { } , config , value , modifiers )
75
81
if ( value !== oldValue ) {
76
- const { config } = el [ CONFIG_KEY ]
77
- el [ CONFIG_KEY ] . config = Object . assign ( { } , config , value , modifiers )
78
82
core . updateValue ( el , vnode , { force : true , clean : true } )
79
83
} else {
80
84
core . updateValue ( el , vnode )
0 commit comments