Clean input on input
This commit is contained in:
parent
09a63ae9eb
commit
3fdfb96e6d
1 changed files with 20 additions and 1 deletions
21
js/calc.js
21
js/calc.js
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
let display = document.querySelector("input.view");
|
let display = document.querySelector("input.view");
|
||||||
let justEvaled = false;
|
let justEvaled = false;
|
||||||
|
const validOpts = Array()
|
||||||
|
|
||||||
const isNumeric = (val) => {
|
const isNumeric = (val) => {
|
||||||
return !isNaN(parseInt(val));
|
return !isNaN(parseInt(val));
|
||||||
|
|
@ -43,6 +44,24 @@ const init = () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.querySelectorAll('td').forEach((btn) => {
|
||||||
|
validOpts.push(btn.innerText);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
init();
|
display.addEventListener('input', () => {
|
||||||
|
let newVal = String();
|
||||||
|
|
||||||
|
for (let char of display.value) {
|
||||||
|
if (validOpts.includes(char)) {
|
||||||
|
newVal += char;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
display.value = newVal;
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener('load', () => {
|
||||||
|
init();
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue