@@ -26,8 +26,8 @@ This page demonstrates usage of props and events provided by HOtpInput.
26
26
| onChange | ` Function ` | ` null ` | Callback event that return OTP code when we made a change in inputs. ` (otpCode: string) ` |
27
27
| onFinish | ` Function ` | ` null ` | Callback event that return OTP code when we fully typed all inputs. ` (otpCode: string) ` |
28
28
| separator | ` String ` | ` null ` | Separator to be rendered. |
29
- | separatorType | ` String ` | ` middle ` | Default separator position if separator is not null |
30
-
29
+ | separatorType | ` String ` | ` " middle", "all" ` | Default separator position if separator is not null |
30
+ | genResultWithSeparator | ` Function ` | ` null ` | Using this event, exposed from otp component to get code with separator |
31
31
See the [ Vue3 Simple OTP Input] ( https://www.npmjs.com/package/@healerlab/vue3-simple-otp-input ) package for more information.
32
32
33
33
@@ -43,12 +43,15 @@ const { HOtpInput } = pkg
43
43
const otpInput = ref (null )
44
44
const otpCode = ref ()
45
45
const otpCodeChange = ref ()
46
+ const otpWithSeparator = ref ()
46
47
47
48
const handleFinish = (code : string ) => {
48
49
otpCode .value = code
50
+ otpWithSeparator .value = otpInput? .value ? .genResultWithSeparator ()
49
51
}
50
52
51
53
const handleChange = (code : string ) => {
54
+ otpWithSeparator .value = ' '
52
55
otpCodeChange .value = code
53
56
if (! code) otpCode .value = ' '
54
57
}
@@ -65,6 +68,7 @@ const isReadonly = ref(false)
65
68
const isAllowPaste = ref (false )
66
69
const otpLength = ref (6 )
67
70
const currentOtpType = ref (' text' )
71
+ const currentSeparator = ref (' middle' )
68
72
69
73
const changeOnlyNumber = () => {
70
74
otpInput .value .clear ()
@@ -78,6 +82,8 @@ const changeOTPLength = (isInCrease: boolean) => {
78
82
const changeOtpType = () => {
79
83
currentOtpType .value = currentOtpType .value === " password" ? " text" : " password"
80
84
}
85
+
86
+ const changeSeparator = () => currentSeparator .value = currentSeparator .value === " middle" ? " all" : " middle"
81
87
< / script>
82
88
< label> Current OTP Length is: ` {{ otpLength }}` < / label> < br / >
83
89
< label>< input type= " checkbox" : checked= " isOutlined" @change= " isOutlined = !isOutlined" > Outlined< / label>
@@ -87,6 +93,7 @@ const changeOtpType = () => {
87
93
< label>< input type= " checkbox" : checked= " isReadonly" @change= " isReadonly = !isReadonly" > Readonly< / label>
88
94
< label>< input type= " checkbox" : checked= " isAllowPaste" @change= " isAllowPaste = !isAllowPaste" > AllowPaste< / label> < br / >
89
95
< label>< input type= " checkbox" @change= " changeOtpType" > OTP type: ` {{ currentOtpType }}` < / label> < br / >
96
+ < label>< input type= " checkbox" @change= " changeSeparator" > Separator: ` {{ currentSeparator }}` < / label> < br / >
90
97
91
98
92
99
< a @click= " changeOTPLength(false)" href= " javascript:void(0)" > Change OTP Length to 4 < / a>
@@ -107,10 +114,14 @@ const changeOtpType = () => {
107
114
: disabled= " isDisabled"
108
115
: readonly= " isReadonly"
109
116
: allowPaste= " isAllowPaste"
117
+ : separatorType= " currentSeparator"
118
+ separator= " -"
110
119
/ >
111
120
<!-- Using
112
121
< button @click= " clearOtp" > Clear OTP < / button> -->
113
122
114
123
< span> The final OTP code is: ` {{ otpCode }}` < / span>
115
124
< br / >
116
- <span >The OTP changed to: ` {{ otpCodeChange }} ` </span >
125
+ < span> The OTP changed to: ` {{ otpCodeChange }}` < / span>
126
+ < br / >
127
+ < span> The OTP with separator: ` {{ otpWithSeparator }}` < / span> (get code by calling genResultWithSeparator () exposed from otp component)
0 commit comments