From 8ed28b4c3b6b7c64a9048677b2448949144a95bd Mon Sep 17 00:00:00 2001 From: Ritika-Agrawal0811 Date: Sat, 13 Feb 2021 19:07:29 +0530 Subject: [PATCH] v0.30.81 feat (user) : feature to input login pin --- scripts/script.js | 112 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/scripts/script.js b/scripts/script.js index e69de29..61ae78e 100644 --- a/scripts/script.js +++ b/scripts/script.js @@ -0,0 +1,112 @@ +const pinLogin = document.createElement('template'); +pinLogin.innerHTML = ` + + +
+ +`; + +customElements.define('login-pin', + + class extends HTMLElement { + constructor() { + super() + this.attachShadow({ + mode: 'open' + }).append(pinLogin.content.cloneNode(true)) + + this.pin_block = []; + this.container = this.shadowRoot.querySelector('.pin-container'); + } + + renderBlocks(){ + const frag = document.createDocumentFragment(); + + for(let i=0 ; i<4;i++){ + + const password = document.createElement('input'); + password.classList.add('input-style'); + password.setAttribute('type', "password"); + password.setAttribute('maxlength', "1"); + + this.pin_block.push(password); + + frag.append(password); + } + + this.container.append(frag); + } + + + connectedCallback() { + this.renderBlocks(); + this.pin_block[0].focus(); + let pin_block = this.pin_block; + let count =0; + this.pin_block.forEach((input) =>{ + input.addEventListener('keydown' , function(e){ + if(e.keyCode >=48 && e.keyCode<= 57){ + if(count>4){ + e.preventDefault(); + } + else{ + + pin_block[count].classList.add('input-pin'); + pin_block[count++].focus(); + } + + } + + if(e.key === "Backspace"){ + if(count <= 0){ + e.preventDefault(); + } + else{ + count--; + pin_block[count].classList.remove('input-pin'); + pin_block[count].focus(); + + } + + } + }); + }); + + } + + + }); \ No newline at end of file