Git Product home page Git Product logo

bootstrap-pincode-input's Introduction

Bootstrap pincode-input

Bootstrap jQuery widget for x-digit pincode input

You only need a <input type="text"> and Bootstrap.

After entering a pincode the value will be updated in the original textbox. It supports a callback after all digits are entered and backspace is allowed. See Usage below this page to find out all parameters

For touch devices there will be only one input tag created. With the supplied CSS it will look like the user is inputting a code in multiple input boxes.

Demo

A demo can be found at fkranenburg.github.io/bootstrap-pincode-input

screenshot

Installation

You can install bootstrap-pincode-input by using npm:

npm install --save bootstrap-pincode-input

Usage

inputs

Number. Default: 0

Length of to be entered code. For every digit a input box will be created and visibile for the user.

<input type="text" name="mycode" id="pincode-input1">

This function will create, for example, an input box with 4 digits.

$('#pincode-input1').pincodeInput({inputs:4});

placeholders

String. Default: null

Place placeholders in every input. Make sure you define a placeholder for each input seperated with a space. For example an input with 3 digits, placeholders are defined like 1 2 3.

<input type="text" name="mycode" id="pincode-input1">
$('#pincode-input1').pincodeInput({inputs:2,placeholders:"0 0 0"});

hidedigits

Boolean. Default: true

By default entered digits are hidden visually (like a password input) for the user. This can be overriden by setting this to false.

<input type="text" name="mycode" id="pincode-input1">
$('#pincode-input1').pincodeInput({inputs:4,hidedigits:false});

keydown

@deprecated since 1.3.0 -> will be removed in a later release. Use change event instead.

Callback function for keydown event for each input box. The keydown event is passed to the callback.

$('#pincode-input1').pincodeInput({keydown:function(e){
  console.log("keydown event fired!",e);
});

change

Callback function for each input box after user enters or removes a digit. The following parameters are passed to the given function.

  • input Element. the DOM input element where user changed a digit.
  • value String. the value entered
  • inputnumber Number. returns the 'position' of the current input.
   $('#pincode-input1').pincodeInput({inputs:4,change: function(input,value,inputnumber){
       console.log("onchange from input number "+inputnumber+", current value: " + value, input);
    }});

complete

Callback function when all input boxes have a value (user has entered the full code). The following parameters are passed to the given function.

  • value String. complete given code as a string.
  • event Event. the last 'keydown' event from last inputbox.
  • errorElement Element. returns the error element where you can put a custom error message for the user, for example the code is invalid.
      $('#pincode-input1').pincodeInput({inputs:6,complete:function(value, e, errorElement){
          console.log("code entered: " + value);
          
          /*do some code checking here*/
          
          $(errorElement).html("I'm sorry, but the code not correct");
        }});

License

This plugin is available under the [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0

Created by Ferry Kranenburg

bootstrap-pincode-input's People

Contributors

banjerluke avatar ctmaloney avatar dependabot[bot] avatar ferchoz avatar fkranenburg avatar isaacd9 avatar itaybb avatar janwillemm avatar rimas-kudelis avatar troyhy avatar xandomm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bootstrap-pincode-input's Issues

Zero number cannot entered on un-english keyboards

If I use un-english keyboard (Hungarian) the 0 number cannot be entered in the input field.
I had to change it to english - keyboard inout source and then back.
Is there any hack for handle this issue?

On paste cursor moves to third position

Hi!

On paste cursor moves to a third digit position.

Would make more sense to have it at the end of input or don't have it at all, or is this a bug?

Thanks in advance!

Reset

How do you reset or clear the entered pin?

Let's say a user has submitted an incorrect pin. And you don't want them to hit backspace till they clear the entire input.

I've tried $('#input').val(''); and $('#input').trigger(':reset');. I'm using jquery. Am I missing something?

Placeholders

Adding a placeholder would be awesome. It should do the same as setting a value and split it across all input boxes, e.g:

<input class="pincode-4" name="pincode" type="text" id="field-pincode" placeholder="1234">

Would put placeholders in each input as 1, 2, 3, 4

Problem with script name in package.json installed from npm

package.json contains different script name js/bootstrap-pincode.input.js:

{
  "_args": [
    [
      "bootstrap-pincode-input"
    ]
  ],
  "_from": "bootstrap-pincode-input@latest",
  "_id": "[email protected]",
  "_inCache": true,
  "_installable": true,
  "_location": "/bootstrap-pincode-input",
  "_nodeVersion": "0.12.7",
  "_npmOperationalInternal": {
    "host": "packages-16-east.internal.npmjs.com",
    "tmp": "tmp/bootstrap-pincode-input-1.2.1.tgz_1475519365475_0.2813280050177127"
  },
  "_npmUser": {
    "email": "[email protected]",
    "name": "fkranenburg"
  },
  "_npmVersion": "2.11.3",
  "_phantomChildren": {},
  "_requested": {
    "name": "bootstrap-pincode-input",
    "raw": "bootstrap-pincode-input",
    "rawSpec": "",
    "scope": null,
    "spec": "latest",
    "type": "tag"
  },
  "_requiredBy": [
    "/"
  ],
  "_resolved": "https://registry.npmjs.org/bootstrap-pincode-input/-/bootstrap-pincode-input-1.2.1.tgz",
  "_shasum": "e05ca29f64e615c1256264e28e36c7349d86afea",
  "_shrinkwrap": null,
  "_spec": "bootstrap-pincode-input",
  "author": {
    "name": "Ferry Kranenburg"
  },
  "bugs": {
    "url": "https://github.com/fkranenburg/bootstrap-pincode-input/issues"
  },
  "dependencies": {},
  "description": "Bootstrap jQuery widget for x-digit pincode input",
  "devDependencies": {},
  "directories": {},
  "dist": {
    "shasum": "e05ca29f64e615c1256264e28e36c7349d86afea",
    "tarball": "https://registry.npmjs.org/bootstrap-pincode-input/-/bootstrap-pincode-input-1.2.1.tgz"
  },
  "gitHead": "d62c82634727c10efa5e95f4c5c206054c96a7c3",
  "homepage": "https://github.com/fkranenburg/bootstrap-pincode-input",
  "keywords": [
    "pincode",
    "bootstrap pincode",
    "bootstrap pincode input",
    "jQuery",
    "jquery-plugin"
  ],
  "license": "Apache-2.0",
  "main": "js/bootstrap-pincode.input.js",
  "maintainers": [
    {
      "email": "[email protected]",
      "name": "fkranenburg"
    }
  ],
  "name": "bootstrap-pincode-input",
  "optionalDependencies": {},
  "readme": "ERROR: No README data found!",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/fkranenburg/bootstrap-pincode-input.git"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "version": "1.2.1"
}

no border = invisible input element on touch/modal case

I've tried the new version 3.0 and have run into an issue specific to the case where the input is on a touch device (iPhone or Chrome simulation for me), and is inside a bootstrap modal. On initialization, the input is briefly visible (meaning its border), but then disappears (meaning the border is styled to 0px). The input is still there and functional should the user be hardy enough to try it.

Sample html/js below. Please let me know if you need any more specifics. (and btw - thank you for the previous replies/fixes ;-)).

{{-- Bootstrap modal for PIN code entry --}}
<div id="modal-enter-pin" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">PIN Code Required</h4>
            </div>
            <div class="modal-body" style="width: 200px;">
                <input type="text" id="pin" name="pin" autocomplete="one-time-code">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

JS to display it:

var pinInit = false;        
$('#modal-enter-pin').on('shown.bs.modal', function (e) {
    if (!pinInit) {
        $('#pin').pincodeInput({
            inputs: 4,
            complete: handleModalSubmit
        });
        pinInit = true;
    }
}

$('#modal-enter-pin').modal('show');

Adjust letter spacing when the pincode is opened in a modal

when adding a pin code in a modal asynchronously, the letter spacing is not taken into account because the rendering is not yet done when the JS code retrieves the width of input fields.

It would be good to make a detection of the location of the field and if it is in a modal, launch computation after the opening of the modal.

Null value when the PIN is pasted instead of typed - Chrome, Android

I'm getting a null value posted to my server when the PIN code is pasted in, instead of being typed in.

I am using this plugin to let users enter an OTP. Since Android allows user to copy the code directly from the notification, a lot of users who were pasting it in using this method were getting their OTP invalidated. So I want through my logs to find out the the value for this field was null in the form data being submitted.

I have only tested on Chrome on Android but some of my iOS users have also reported the issue.

Change event

Would be nice to have 'change' event, so one can validate entered value every time code is edited

Bower package

Hey Ferry, are you considering creating a bower package? I think it would be awesome.

Fails on touch devices if initialized while input is hidden

To reproduce:

  1. Modify demo HTML so the input is initially hidden prior to initialization:
<div id="wrapper" style="display: none;">
    <input type="text" name="mycode" id="pincode-input1">
</div>
  1. Modify demo JS so it is displayed following initialization:
$('#pincode-input1').pincodeInput({inputs:4});
$('#wrapper').css('display', 'block');

Observed:

  • Entry works as normal on non-touch devices
  • On touch devices (I tested on iPhone and Chrome debugger phone view): First digit is accepted and mask displayed. Subsequent digits are received and processed internally with no updates rendered on screen. The complete callback will be called once complete, although only the single digit will still be visible on the screen.

Comment:

  • Current workaround is to initialize only while visible, although this is less ideal in that at least in my app, it can result in a visible on-screen change while the original input is transformed.

Working on Tablet and Mobile phone

Hi,
It seems the code works fine for desktop but when it's used on Android devices the rendering is messed up. I tested the same code on iPad and Mac and PC and Android chrome all worked fine except Android Chrome!
Any idea?

Amir

Paste with Ctrl + V

Hello.
I was thinking of adding the code of the Ctrl key in the if of keyup and keydown, but before doing it, I think it's prudent to check if it's not there for some reason.

On touch (only), digits flash/move on PIN completion

To Reproduce:

  1. View the demo page on a touch device such as iPhone or Chrome debugger phone view
  2. Enter 4 digits into the first example

Observed:

  1. After the 4th digit is entered, all the digits briefly right-justify within their boxes, then snap back to the prior position. (touch only - does not happen in non-touch version.)
  2. (In my app, a final line in the complete callback to focus the next input also fails, again on touch only, although I can't prove that's not an issue with my app.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.