0.7.0 • Published 3 years ago

sinchar v0.7.0

Weekly downloads
94
License
ISC
Repository
github
Last release
3 years ago

singleDigitInput

Small utility to controll single char input field. Works well on desktop and mobile devices.

Supports paste event with Ctrl+C. After paste event fired, the callback function executes.

Visually it looks something like this. After filling up all the inputs a callback function executes.

example

Run npm i sinchar to install as npm package.

OR

Embed it via script tag

<script src="https://unpkg.com/sinchar@latest/dist/index.js"></script>

Usage

Imagine structure like this:

<div class="inputs-div">
  <input class="my-input" maxlength="1">
  <input class="my-input" maxlength="1">
  <input class="my-input" maxlength="1">
  <input class="my-input" maxlength="1">
  <input class="my-input" maxlength="1">
  <input class="my-input" maxlength="1">
  <input type="hidden" id="final-value">
</div>

It has 6 inputs for typing in 1 digit per input. For exapmle it can be authorization sms code.

Create instance and pass options object. After instance is created, run .processCodeInput(callback) method. This will initialize all the keyboard events. Please notice, that you have to pass the final value argument to the callback result as shown in example below.

const options = {
  selector: '.inputs-div > .my-input',
  hiddenInputId: 'final-value',
  fillRecievedValue: true
}
const sch = new SinChar(options);
sch.processCodeInput((res) => {
  // res is the final value
  // Here is your code...
});

Options:

OptionTypeRequiredDescription
selectorstringyesCSS selector to pick all inputs. It is a querySelectorAll underhood.
hiddenInputIdstringyesID attribute of a hidden input. This input stores all the digits we entered.
fillRecievedValuebooleanyesIf true, inputs will be filled in case hiddenInput input value is not empty.
filledClassstringnoName of a class to decorate filled input. This is optional parameter.
numbersOnlybooleannoIf true only numbers allowed. Default is false.
autofocusbooleannoIf true first input will be fucused automatically. Default is false.
0.7.0

3 years ago

0.6.1

3 years ago

0.5.3

3 years ago

0.4.4

3 years ago

0.5.0

3 years ago

0.4.3

3 years ago

0.4.1

3 years ago

0.4.2

3 years ago

0.4.0

3 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.1

4 years ago

0.0.20

4 years ago

0.0.21

4 years ago

0.0.22

4 years ago

0.0.23

4 years ago

0.0.18

4 years ago

0.0.19

4 years ago

0.1.0

4 years ago

0.0.17

4 years ago

0.0.16

4 years ago

0.0.15

4 years ago

0.0.14

4 years ago

0.0.10

4 years ago

0.0.11

4 years ago

0.0.13

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

1.0.0

4 years ago