DevilsAutumn / Opensource-init

Repository made for first time contributors.
Apache License 2.0
4 stars 23 forks source link

Fixed- Allow only numbers in input field #26

Closed kunal00000 closed 1 year ago

kunal00000 commented 1 year ago

Description

Please include a summary of the change and which issue is fixed.

Fixes #18

Replace issue_no with the issue number which is fixed in this PR

Type of change

Please delete options that are not relevant.

Checklist:

kunal00000 commented 1 year ago

You can merge this branch now.

DevilsAutumn commented 1 year ago

I think it still needs improvement. Screenshot 2022-10-05 173949

kunal00000 commented 1 year ago

@DevilsAutumn review it once. on pressing keys faster it may leave boxes but while verifying codes we press it slowly. so have a look.

DevilsAutumn commented 1 year ago

@DevilsAutumn review it once. on pressing keys faster it may leave boxes but while verifying codes we press it slowly. so have a look.

try this logic in your js file and see if it causes any error.

codes.forEach((code, idx) => {
  code.addEventListener("keydown", (e) => {
    if (e.keyCode >= 48 && e.keyCode <= 57 && codes[idx].value == "") {
      setTimeout(() => codes[idx + 1].focus(), 10);
    } else if (e.key === "Backspace") {
      codes[idx - 1].value = "";
      setTimeout(() => codes[idx - 1].focus(), 10);
    } else if (e.key === "Enter") {
      for (var i = 0; i < codes.length; i++) {
        codes[i].value = "";
      }
      codes[0].focus();
    } else {
      codes[idx].value = "";
      codes[idx].value = e.key;
      e.preventDefault();
    }
  });
});
kunal00000 commented 1 year ago

yes, it worked flawlessly. Thanks , I got to learn new stuffs from this. maxlength , keyup keydown , preventDefault properties and working. 👍🏻

DevilsAutumn commented 1 year ago

yes, it worked flawlessly. Thanks , I got to learn new stuffs from this. maxlength , keyup keydown , preventDefault properties and working. 👍🏻

Thats great!