@@ -26,8 +26,8 @@ This page demonstrates usage of props and events provided by HOtpInput.
2626| onChange | ` Function ` | ` null ` | Callback event that return OTP code when we made a change in inputs. ` (otpCode: string) ` |
2727| onFinish | ` Function ` | ` null ` | Callback event that return OTP code when we fully typed all inputs. ` (otpCode: string) ` |
2828| 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 |
3131See the [ Vue3 Simple OTP Input] ( https://www.npmjs.com/package/@healerlab/vue3-simple-otp-input ) package for more information.
3232
3333
@@ -43,12 +43,15 @@ const { HOtpInput } = pkg
4343const otpInput = ref (null )
4444const otpCode = ref ()
4545const otpCodeChange = ref ()
46+ const otpWithSeparator = ref ()
4647
4748const handleFinish = (code : string ) => {
4849 otpCode .value = code
50+ otpWithSeparator .value = otpInput? .value ? .genResultWithSeparator ()
4951}
5052
5153const handleChange = (code : string ) => {
54+ otpWithSeparator .value = ' '
5255 otpCodeChange .value = code
5356 if (! code) otpCode .value = ' '
5457}
@@ -65,6 +68,7 @@ const isReadonly = ref(false)
6568const isAllowPaste = ref (false )
6669const otpLength = ref (6 )
6770const currentOtpType = ref (' text' )
71+ const currentSeparator = ref (' middle' )
6872
6973const changeOnlyNumber = () => {
7074 otpInput .value .clear ()
@@ -78,6 +82,8 @@ const changeOTPLength = (isInCrease: boolean) => {
7882const changeOtpType = () => {
7983 currentOtpType .value = currentOtpType .value === " password" ? " text" : " password"
8084}
85+
86+ const changeSeparator = () => currentSeparator .value = currentSeparator .value === " middle" ? " all" : " middle"
8187< / script>
8288< label> Current OTP Length is: ` {{ otpLength }}` < / label> < br / >
8389< label>< input type= " checkbox" : checked= " isOutlined" @change= " isOutlined = !isOutlined" > Outlined< / label>
@@ -87,6 +93,7 @@ const changeOtpType = () => {
8793< label>< input type= " checkbox" : checked= " isReadonly" @change= " isReadonly = !isReadonly" > Readonly< / label>
8894< label>< input type= " checkbox" : checked= " isAllowPaste" @change= " isAllowPaste = !isAllowPaste" > AllowPaste< / label> < br / >
8995< label>< input type= " checkbox" @change= " changeOtpType" > OTP type: ` {{ currentOtpType }}` < / label> < br / >
96+ < label>< input type= " checkbox" @change= " changeSeparator" > Separator: ` {{ currentSeparator }}` < / label> < br / >
9097
9198
9299< a @click= " changeOTPLength(false)" href= " javascript:void(0)" > Change OTP Length to 4 < / a>
@@ -107,10 +114,14 @@ const changeOtpType = () => {
107114 : disabled= " isDisabled"
108115 : readonly= " isReadonly"
109116 : allowPaste= " isAllowPaste"
117+ : separatorType= " currentSeparator"
118+ separator= " -"
110119/ >
111120<!-- Using
112121< button @click= " clearOtp" > Clear OTP < / button> -->
113122
114123< span> The final OTP code is: ` {{ otpCode }}` < / span>
115124< 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