Describe the bug
In the buying credits for listing page, the amount input can't be filled using number key on keyboard.
On the JS code, there's:
document.getElementById("amount-input").addEventListener("keydown",function (e) {
if ((e.keyCode < 48 || e.keyCode > 57) && e.keyCode != 8) {
e.preventDefault();
}
calculatePriceAndShow();
});
The preventDefault
function is wrongfully called. I don't get what it's used for anyway.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
I should be able to enter any amount.
@GMartigny the condition is there to only allow English numbers. If it's not there you can input any number from other languages. I was able to put 郾鄄鄢鄞鄣鄱鄯鄹酃郯(which is 1234567890 in Farsi) without the condition and it's still valid number. Take a look below:
However, the condition won't allow for keypad numbers because keypad 0-9 is keycode 96
to 105
. I believe the correct function should be this:
function listenForNumberChange() {
document.getElementById("amount-input").addEventListener("keydown",function (e) {
(
(e.keyCode >= 48 && e.keyCode <= 57) || // Keyboard 0-9 Keycode is 48 to 57
(e.keyCode >= 96 && e.keyCode <= 105) || //Keypad 0-9 Keycode is 96 to 105
(e.keyCode == 8) //Allow backspace
) ?
calculatePriceAndShow():
e.preventDefault();
});
}
Ok, but why prevent typing farsi numbers ? JS seems to understand the input value correctly and display the right amount (3086419725 $) on the right of the input.
IMO, the website should not prevent user actions, but they should be sanitized on the back-end.
resolved with PR #2672