Как заставить работать данный код со всеми input?
const InputFormatType = {
THOUSAND: 3
};
const decorator = ( value, format = InputFormatType.THOUSAND ) => value
.split( '' )
.filter( char => char !== " " )
.reverse()
.reduce( ( result, char, index ) => result += (( index >= format && index % format === 0 ? " " : "" ) + char), "" )
.split( '' )
.reverse()
.join( '' );
const input = document.body.querySelector('input');
input.addEventListener('input', input_inputHandler);
function input_inputHandler( { target } ){
target.value = decorator( target.value );
}
<input type="text" class="input">
<input type="text" class="input">
const InputFormatType = {
THOUSAND: 3
};
const decorator = ( value, format = InputFormatType.THOUSAND ) => value
.split( '' )
.filter( char => char !== " " )
.reverse()
.reduce( ( result, char, index ) => result += (( index >= format && index % format === 0 ? " " : "" ) + char), "" )
.split( '' )
.reverse()
.join( '' );
// Выбираем все элементы селектора
const inputs = document.body.querySelectorAll('input');
// Перебираем элементы, навешивая на каждый обработчик события
inputs.forEach(function(input) {
input.addEventListener('input', input_inputHandler);
});
function input_inputHandler( { target } ){
target.value = decorator( target.value );
}
<input type="text" class="input">
<input type="text" class="input">
Кофе для программистов: как напиток влияет на продуктивность кодеров?
Рекламные вывески: как привлечь внимание и увеличить продажи
Стратегії та тренди в SMM - Технології, що формують майбутнє сьогодні
Выделенный сервер, что это, для чего нужен и какие характеристики важны?
Современные решения для бизнеса: как облачные и виртуальные технологии меняют рынок
Есть глобальные объект, который пытаюсь заполнять на фронте собирая данные из checkbox для отправки на север