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', () => {
|
||||
$(this).addClass('touched');
|
||||
delegate('blur keydown', 'input, textarea', ({ target }) => {
|
||||
touch(target);
|
||||
});
|
||||
|
||||
$(document).on('click', 'input[type="submit"]:not([formnovalidate])', () => {
|
||||
const $form = $(this).closest('form');
|
||||
$('input, textarea', $form).addClass('touched');
|
||||
});
|
||||
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');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue