-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform.js
63 lines (58 loc) · 2.44 KB
/
form.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
$(document).ready(function() {
$('#quote-given-yes').click(function() {
$("#quoteGivenEnter").fadeIn();
});
$('#quote-given-no').parent().click(function() {
$("#quoteGivenEnter").fadeOut();
$("#quoteGivenEnter").val('');
});
$('.submit').click(function() {
validateForm();
$('input[required=""]').on("input", function() {
validateForm();
});
$('.form-choice-selector[required=""]').on('click', function() {
validateForm();
});
$('select').on("change", function() {
validateForm();
});
return false;
});
function validateForm() {
console.log('validate');
$('form').addClass('is-validated');
var inputs = $('input[required=""]');
inputs.each(function(index) {
if ($(this).val() === "") {
$(this).addClass('is-error');
$(this).parent().find('.form-message-wrapper').first().show();
} else {
if ($(this).attr('type') === 'email') {
$(this).removeClass('is-error');
$(this).parent().find('.form-message-wrapper').first().hide();
if ($("input[name='email']:valid").length === 0) {
$("input[name='email']").addClass('is-error-pattern');
$("#businessTeamForm-email-error-invalid").parent().show();
} else {
$("input[name='email']").removeClass('is-error-pattern');
$("#businessTeamForm-email-error-invalid").parent().hide();
}
} else {
$(this).removeClass('is-error');
$(this).parent().find('.form-message-wrapper').first().hide();
}
}
});
if ($('input[name="contactType"]:checked').length === 0) {
$('input[name="contactType"]').closest('.form-fieldset').addClass('is-error').find('.form-message-wrapper').show();
} else {
$('input[name="contactType"]').closest('.form-fieldset').removeClass('is-error').find('.form-message-wrapper').hide();
}
if ($('select').val() === null) {
$('select').addClass('is-error').parent().find('.form-message-wrapper').show();
} else {
$('select').removeClass('is-error').parent().find('.form-message-wrapper').hide();
}
}
});