demarches-normaliennes/app/javascript/new_design/form-validation.js

20 lines
421 B
JavaScript
Raw Normal View History

2018-10-09 11:43:25 +02:00
import { delegate } from '@utils';
2018-08-09 11:53:59 +02:00
2018-10-09 11:43:25 +02:00
delegate('blur keydown', 'input, textarea', ({ target }) => {
touch(target);
});
2018-10-09 11:43:25 +02:00
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');
}