Refactor form validation helpers
This commit is contained in:
parent
8c16eb4cd0
commit
d18b1c8ddc
1 changed files with 16 additions and 7 deletions
|
@ -1,10 +1,19 @@
|
||||||
import $ from 'jquery';
|
import { delegate } from '@utils';
|
||||||
|
|
||||||
$(document).on('blur keydown', 'input, textarea', () => {
|
delegate('blur keydown', 'input, textarea', ({ target }) => {
|
||||||
$(this).addClass('touched');
|
touch(target);
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on('click', 'input[type="submit"]:not([formnovalidate])', () => {
|
delegate(
|
||||||
const $form = $(this).closest('form');
|
'click',
|
||||||
$('input, textarea', $form).addClass('touched');
|
'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');
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue