import validate from utils validation export default form let form for

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import validate from '../utils/validation';
export default (form) => {
let $form = $(form) || $(form).find('form');
if ($form.length <= 0) {
console.error('Form not found');
return false;
}
let pristine = new Pristine(form);
let isValid = false;
$form.on('submit', (e) => {
isValid = validate($form[0]);
if (!isValid) {
e.preventDefault();
} else {
if (form.hasAttribute('data-metric')) {
let tag = form.getAttribute('data-metric-tag');
try {
gtag("event" , "event_name", { "event_category": tag, "event_action": "send"});
ym(54609001, 'reachGoal', tag);
}
catch (e) {
console.log(e);
}
}
console.log('Form is valid!');
}
});
}