0.0.2 • Published 9 months ago

v3-pin-input v0.0.2

Weekly downloads
-
License
-
Repository
-
Last release
9 months ago

pin-input

PIN-Input is a Vue component o capture PIN/MPIN like input

Demo

Live example here

Installation

npm install v3-pin-input --save

Usage

// index.js
import { createApp } from "vue";
import App from "./App.vue";
import PinInput from "/node_modules/v3-pin-input/dist/pin-input.es";
import "/node_modules/v3-pin-input/dist/style.css";

const app = createApp(App);
app.use(PinInput);
app.mount("#app");
<!-- vue component -->
<template>
  <form @submit="onSubmit">
    <pin-input
      :count="6"
      :defaultValue="inputValue"
      :hidden="false"
      @on-change="onChange"
      @on-error="onError"
    />
  </form>
</template>

<script>
  export default {
    name: "component",
    data() {
      return {
        inputValue: 6,
      };
    },
    methods: {
      onChange(newInputValue) {
        this.inputValue = Number(newInputValue);
      },
      onClear() {
        this.inputValue = "";
      },
      onError(message) {
        alert(message);
      },
      onSubmit(e) {
        e.preventDefault();
        alert(`newInputValue: ${this.inputValue}`);
      },
    },
  };
</script>

Props:

PropertyTypeDescription
countnumberthe number of symbols in the pin code
defaultValuestringOptional parameter. The default value to be entered in the inputs
hiddenbooleanDo I need to hide characters during user input (type="password")

Methods:

PropertyEventDescription
@on-changestringtriggered when the user changes the field. Returns the new pin-code value
@on-errorstringTriggered when data is entered incorrectly. Returns an error message