2018-10-09 11:35:22 +02:00
|
|
|
import { delegate, fire, debounce } from '@utils';
|
2018-08-28 16:42:16 +02:00
|
|
|
|
|
|
|
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));
|