demarches-normaliennes/app/javascript/new_design/form-validation.js
2018-10-10 14:55:28 +02:00

19 lines
421 B
JavaScript

import { delegate } from '@utils';
delegate('blur keydown', 'input, textarea', ({ target }) => {
touch(target);
});
delegate(
'click',
'input[type="submit"]:not([formnovalidate])',
({ target }) => {
let form = target.closest('form');
let inputs = form ? form.querySelectorAll('input, textarea') : [];
[...inputs].forEach(touch);
}
);
function touch({ classList }) {
classList.add('touched');
}