Javascript cross-browser and flexible pincode login input experience
npm install pinlogindemo folder and view the contents of the index.html file.
npm install --save pinlogin
javascript
var pinlogin = new Pinlogin(document.querySelector('#element'), {
fields: 5,
complete : function(pin){
alert ('Awesome! You entered: ' + pin);
// further processing here
}
});
`
$3
1. Include code:
`html
`
2. Include css:
`html
`
3. Call the plugin:
`javascript
var pinlogin = new Pinlogin(document.querySelector('#element'), {
fields: 5,
complete : function(pin){
alert ('Awesome! You entered: ' + pin);
// further processing here
}
});
`
$3
1. Include jQuery:
`html
`
2. Include plugin's code:
`html
`
2. Include plugin's css:
`html
`
3. Call the plugin:
`javascript
var pinlogin = $("#element").pinlogin({
fields: 5,
complete : function(pin){
alert ('Awesome! You entered: ' + pin);
// further processing here
}
});
`
Usage
$3
Number. Default 5
The amount of pincode input fields where the user needs to enter a pin code.
$3
String. Default •
Contains the placeholder that's displayed instead of the entered digits. You can use special characters, but if you do make sure your HTML page is properly encoded. For example UTF8:
`html
`
$3
Boolean. Default true.
When the plugin is loaded, automatically focus on the first input field.
$3
Boolean. Default true.
Hides or displays the user entered digits in the input field. When enabled, the caharacter in placeholder immediately replaces the entered digit.
$3
Boolean. Default true.
When true, this resets all input fields when filled.
$3
String. Default ^[0-9]*$.
A regular expression that is used to match the entered value in the input field. If no match, the entered value will be considered incorrect.
$3
Boolean. Default true.
This determines whether it is possible to paste a copied pincode into the pinlogin fields. It also checks for invalid input using the pattern. Note that this will only work when:
* it is pasted into the first field
* the length of the pasted string is exact the same as the number of fields
$3
Callback function that will fire when all input fields are filled.
Passed parameters:
* `pin` String. The entered pincode.
`javascript
$('#element').pinlogin({
complete : function(pin){
console.log('You entered: ' + pin);
}});
`
$3
Callback function that will fire when user enters an invalid character in a pincode field.
Passed parameters:
* `field` Element. The object of the field that's invalid.
* `nr` Number. The number of the field that's invalid (start counting at 0).
`javascript
$('#element').pinlogin({
invalid : function(field, nr){
console.log('The field with nr : ' + nr + ' contains an invalid character');
}});
`
$3
Callback function that will fire when user presses the key, and right before it reaches the pincode field.
Passed parameters:
* `e` Event. The 'keydown' event.
* `field` Element. The object of the field that's getting the keydown.
* `nr` Number. The number of the field that's getting the keydown (start counting at 0).
`javascript
$('#element').pinlogin({
keydown : function(e, field, nr){
console.log('The field with nr : ' + nr + ' is about to get a value');
}});
`
Public methods
If you assign Pinlogin to a variable the jQuery element to a variable, for example var pinlogin = new Pinlogin(...); it's possible to use some public methods, explained below, so you can alter the behaviour of Pinlogin. Look at the demo to see an example use case for the usage of the public methods described below.
$3
Returns the ID of the field
Parameters:
* `nr` Number. The number of the fields' ID to be returned (start counting at 0).
$3
Returns the field Object
Parameters:
* `nr` Number. The number of the fields' Object to be returned (start counting at 0).
$3
Resets the whole instance and all the input fields.
$3
Reset a single input field.
Parameters:
* `nr` Number. The number of the field that will be reset (start counting at 0).
$3
Disables the whole instance and all the input fields.
$3
Disable a single input field.
Parameters:
* `nr` Number. The number of the field that will be disabled (start counting at 0).
$3
Enables the whole instance and all the input fields.
$3
Enable a single input field.
Parameters:
* `nr` Number. The number of the field that will be enabled (start counting at 0).
$3
Focus on the specified input field.
Parameters:
* `nr` Number. The number of the field that will recieve focus (start counting at 0).
$3
Validates the input of the specified field using pattern.
Parameters:
* `nr`` Number. The number of the field that will recieve focus (start counting at 0).