@@ -49,7 +49,6 @@ export default baseMixins.extend<options>().extend({
49
49
} ,
50
50
51
51
data : ( ) => ( {
52
- badInput : false ,
53
52
initialValue : null ,
54
53
isBooted : false ,
55
54
otp : [ ] as string [ ] ,
@@ -66,9 +65,6 @@ export default baseMixins.extend<options>().extend({
66
65
'v-otp-input--plain' : this . plain ,
67
66
}
68
67
} ,
69
- isDirty ( ) : boolean {
70
- return VInput . options . computed . isDirty . call ( this ) || this . badInput
71
- } ,
72
68
} ,
73
69
74
70
watch : {
@@ -159,18 +155,17 @@ export default baseMixins.extend<options>().extend({
159
155
} ,
160
156
attrs : {
161
157
...this . attrs$ ,
158
+ autocomplete : 'one-time-code' ,
162
159
disabled : this . isDisabled ,
163
160
readonly : this . isReadonly ,
164
161
type : this . type ,
165
162
id : `${ this . computedId } --${ otpIdx } ` ,
166
163
class : `otp-field-box--${ otpIdx } ` ,
167
- maxlength : 1 ,
168
164
} ,
169
165
on : Object . assign ( listeners , {
170
166
blur : this . onBlur ,
171
167
input : ( e : Event ) => this . onInput ( e , otpIdx ) ,
172
168
focus : ( e : Event ) => this . onFocus ( e , otpIdx ) ,
173
- paste : ( e : ClipboardEvent ) => this . onPaste ( e , otpIdx ) ,
174
169
keydown : this . onKeyDown ,
175
170
keyup : ( e : KeyboardEvent ) => this . onKeyUp ( e , otpIdx ) ,
176
171
} ) ,
@@ -212,22 +207,31 @@ export default baseMixins.extend<options>().extend({
212
207
e && this . $emit ( 'focus' , e )
213
208
}
214
209
} ,
215
- onInput ( e : Event , otpIdx : number ) {
210
+ onInput ( e : Event , index : number ) {
211
+ const maxCursor = + this . length - 1
212
+
216
213
const target = e . target as HTMLInputElement
217
214
const value = target . value
218
- this . applyValue ( otpIdx , target . value , ( ) => {
219
- this . internalValue = this . otp . join ( '' )
220
- } )
221
- this . badInput = target . validity && target . validity . badInput
215
+ const inputDataArray = value ?. split ( '' ) || [ ]
216
+
217
+ const newOtp : string [ ] = [ ...this . otp ]
218
+ for ( let i = 0 ; i < inputDataArray . length ; i ++ ) {
219
+ const appIdx = index + i
220
+ if ( appIdx > maxCursor ) break
221
+ newOtp [ appIdx ] = inputDataArray [ i ] . toString ( )
222
+ }
223
+ if ( ! inputDataArray . length ) {
224
+ newOtp . splice ( index , 1 )
225
+ }
226
+
227
+ this . otp = newOtp
228
+ this . internalValue = this . otp . join ( '' )
222
229
223
- const nextIndex = otpIdx + 1
224
- if ( value ) {
225
- if ( nextIndex < + this . length ) {
226
- this . changeFocus ( nextIndex )
227
- } else {
228
- this . clearFocus ( otpIdx )
229
- this . onCompleted ( )
230
- }
230
+ if ( index + inputDataArray . length >= + this . length ) {
231
+ this . onCompleted ( )
232
+ this . clearFocus ( index )
233
+ } else if ( inputDataArray . length ) {
234
+ this . changeFocus ( index + inputDataArray . length )
231
235
}
232
236
} ,
233
237
clearFocus ( index : number ) {
@@ -255,30 +259,6 @@ export default baseMixins.extend<options>().extend({
255
259
256
260
VInput . options . methods . onMouseUp . call ( this , e )
257
261
} ,
258
- onPaste ( event : ClipboardEvent , index : number ) {
259
- const maxCursor = + this . length - 1
260
- const inputVal = event ?. clipboardData ?. getData ( 'Text' )
261
- const inputDataArray = inputVal ?. split ( '' ) || [ ]
262
- event . preventDefault ( )
263
- const newOtp : string [ ] = [ ...this . otp ]
264
- for ( let i = 0 ; i < inputDataArray . length ; i ++ ) {
265
- const appIdx = index + i
266
- if ( appIdx > maxCursor ) break
267
- newOtp [ appIdx ] = inputDataArray [ i ] . toString ( )
268
- }
269
- this . otp = newOtp
270
- this . internalValue = this . otp . join ( '' )
271
- const targetFocus = Math . min ( index + inputDataArray . length , maxCursor )
272
- this . changeFocus ( targetFocus )
273
-
274
- if ( newOtp . length === + this . length ) { this . onCompleted ( ) ; this . clearFocus ( targetFocus ) }
275
- } ,
276
- applyValue ( index : number , inputVal : string , next : Function ) {
277
- const newOtp : string [ ] = [ ...this . otp ]
278
- newOtp [ index ] = inputVal
279
- this . otp = newOtp
280
- next ( )
281
- } ,
282
262
changeFocus ( index : number ) {
283
263
this . onFocus ( undefined , index || 0 )
284
264
} ,
0 commit comments