Help needed for a newbie. I'm having a hard time deleting white spaces from input in the submit form. Here's the way I tried to do it:
var usernameInput = document.querySelector('.setup-user-name');
var newValue = usernameInput.value.trim();
usernameInput.value = newValue;
After that form should go through validation like that:
usernameInput.addEventListener('invalid', function () {
if (usernameInput.validity.tooShort) {
usernameInput.setCustomValidity('Имя должно состоять минимум из 2-х
символов');
} else if (usernameInput.validity.valueMissing) {
usernameInput.setCustomValidity('Обязательное поле');
} else {
usernameInput.setCustomValidity('');
}
});
Even though I use the trim method I'm still able to submit the form with spaces in the input.