demarches-normaliennes/app/javascript/shared/remote-input.js

22 lines
558 B
JavaScript
Raw Normal View History

2018-10-09 11:35:22 +02:00
import { delegate, fire, debounce } from '@utils';
const remote = 'data-remote';
const inputChangeSelector = `input[${remote}], textarea[${remote}]`;
// This is a patch for ujs remote handler. Its purpose is to add
// a debounced input listener.
function handleRemote(event) {
const element = this;
if (isRemote(element)) {
fire(element, 'change', event);
}
}
function isRemote(element) {
const value = element.getAttribute(remote);
return value && value !== 'false';
}
2018-10-09 11:35:22 +02:00
delegate('input', inputChangeSelector, debounce(handleRemote, 200));