0.1.5 • Published 5 years ago

vue-otp-field v0.1.5

Weekly downloads
42
License
MIT
Repository
github
Last release
5 years ago

vue-otp-field

Input Field for OTP

vue-otp-field props

PropsTypeDefaultDescription
maxNumber1Max length for each input
typeStringtelType of each input
placeholderStringPlaceholder of each input
onFieldCompletedFunctionnullCallback function when user has completed (filled) all input
amountNumber4Amount of input field
onFillFunctionnullCallback function when user type in the value to the field

Instalation

Install the package

yarn add vue-otp-field

or

npm install vue-otp-field

Usage

<template>
  <div id="app">
    <div>
      <VueOTPField :onFieldCompleted="onFieldCompleted" :onFill="onFill" />
    </div>
  </div>
</template>

<script>
import VueOTPField from '@/components/VueOTPField'

export default {
  name: 'app',
  components: {
    VueOTPField
  },
  methods: {
    onFieldCompleted (value) {
      console.log('SUBMITTING')
    },
    onFill (inputObj) {
      console.log(inputObj)
    }
  }
}
</script>

onFieldCompleted method will trigger if the user already fill all the input, and you can get value of all the input

onFill method will trigger whenever user start filling the input, you will get the input object of

KeyTypeDescription
currentValueStringCurrent user typed input
isFieldsCompleteBooleanThe flag whether user has already fill all the input
valuesStringAll input values combined

Example with button

<template>
  <div class="hello">
    <div class="container">
      <VueOTPField :onFill="onFill" />
      <button v-show="showButton" class="btn">Verify</button>
    </div>
  </div>
</template>

<script>
import VueOTPField from 'vue-otp-field'

export default {
  name: 'HelloWorld',
  data () {
    return {
      showButton: false
    }
  },
  components: {
    VueOTPField
  },
  props: {
    msg: String
  },
  methods: {
    onFill (val) {
      val.isFieldsComplete ? this.showButton = true : this.showButton = false
    }
  }
}
</script>

example with button

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago