care_form.js
4.38 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
define(
['jquery'], function ($) {
$(document).ready(
function () {
// Check if browser supports HTML5 input placeholder
function supports_input_placeholder() {
var i = document.createElement('input');
return 'placeholder' in i;
}
// Change input text on focus
if (!supports_input_placeholder()) {
jQuery('.wpcf7-text').each(
function () {
var self = jQuery(this);
var value = jQuery.trim(self.val());
if (value == '') self.val(self.attr('placeholder'));
}
);
jQuery('.wpcf7-text').focus(
function () {
var self = jQuery(this);
if (self.val() == self.attr('placeholder')) self.val('');
}
).blur(
function () {
var self = jQuery(this);
var value = jQuery.trim(self.val());
if (value == '') self.val(self.attr('placeholder'));
}
);
}
//functionality for add-file link
$('a.add_file').on(
'click', function (e) {
//show by click the first one from hidden inputs
$('p.hide:not(:visible):first').show('slow');
e.preventDefault();
}
);
//functionality for del-file link
$('a.del_file').on(
'click', function (e) {
//var init
var input_parent = $(this).parent();
var input_wrap = input_parent.find('span');
//reset field value
input_wrap.html(input_wrap.html());
//hide by click
input_parent.hide('slow');
e.preventDefault();
}
);
$('a.first-file').on(
'click', function (e) {
//reset field value
$('.wpcf7-file').eq(0).replaceWith($('.wpcf7-file').eq(0).val('').clone(true));
$(this).hide();
e.preventDefault();
}
);
$('.wpcf7-file').eq(0).change(
function () {
var fileName = $(this).val();
if (fileName != '') {
$('a.first-file').show();
} else {
$('a.first-file').hide();
}
}
);
var eventFields = $('input[name="event-date"], input[name="event-location"], textarea[name="purpose-event"], input[name="role"], textarea[name="recognize-event"]');
eventFields.removeClass('wpcf7-validates-as-required');
eventFields.parents('.form-control').hide();
$('input[name="donation"]').click(
function () {
var value = $(this).attr('value');
var isDonation = value.indexOf('donation') > 0;
var requiredClassName = 'wpcf7-validates-as-required';
var requiredAttr = "aria-required";
var eventFields = $('input[name="event-date"], input[name="event-location"], textarea[name="purpose-event"], input[name="role"], textarea[name="recognize-event"]');
// Check if it is donation or event
if (!isDonation) {
eventFields.addClass(requiredClassName).attr(requiredAttr, true);
eventFields.parents('.form-control').slideDown();
} else {
eventFields.removeClass(requiredClassName).attr(requiredAttr, false);
eventFields.parents('.form-control').slideUp();
}
}
);
}
);
}
);