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.2 0.2.3
cf7-conditional-fields / js / scripts.js
cf7-conditional-fields / js Last commit date
scripts.js 9 years ago scripts_admin.js 10 years ago
scripts.js
106 lines
1 var cf7signature_resized = 0; // for compatibility with contact-form-7-signature-addon
2
3 (function($) {
4
5 var i=0;
6 var options = [];
7 while (true) {
8 i++;
9 if ('wpcf7cf_options_'+i in window) {
10 options.push(window['wpcf7cf_options_'+i]);
11 continue;
12 }
13 break;
14 }
15
16 $(document).ready(function() {
17 function display_fields(unit_tag, wpcf7cf_conditions) {
18
19 //for compatibility with contact-form-7-signature-addon
20 if (cf7signature_resized == 0 && typeof signatures !== 'undefined' && signatures.constructor === Array && signatures.length > 0 ) {
21 if (signatures[0].canvas.width == 0) {
22 for (var i = 0; i < signatures.length; i++) {
23
24 jQuery(".wpcf7-form-control-signature-body>canvas").eq(0).attr('width', jQuery(".wpcf7-form-control-signature-wrap").width());
25 jQuery(".wpcf7-form-control-signature-body>canvas").eq(0).attr('height', jQuery(".wpcf7-form-control-signature-wrap").height());
26
27 cf7signature_resized = 1;
28 }
29 }
30 }
31
32
33 $("#"+unit_tag+" [data-class='wpcf7cf_group']").hide();
34 for (var i=0; i < wpcf7cf_conditions.length; i++) {
35
36 var condition = wpcf7cf_conditions[i];
37 if (condition.then_visibility == 'hide') continue;
38
39 $field = $('#'+unit_tag+' [name='+condition.if_field+']').length ? $('#'+unit_tag+' [name='+condition.if_field+']') : $('#'+unit_tag+' [name='+condition.if_field+'\\[\\]]');
40
41 if ($field.length == 1) {
42
43 // single field (tested with text field, single checkbox, select with single value (dropdown), select with multiple values)
44
45 if ($field.is('select')) {
46 var show = false;
47 if(condition.operator == 'not equals') {
48 show = true;
49 }
50 $field.find('option:selected').each(function () {
51 var $option = $(this);
52 if (condition.operator == 'equals' && $option.val() == condition.if_value) {
53 show = true;
54 } else if (condition.operator == 'not equals' && $option.val() == condition.if_value) {
55 show = false;
56 }
57 });
58 if(show == true) {
59 $('#' + unit_tag + ' #' + condition.then_field).show();
60 }
61
62 continue;
63 }
64
65 if (condition.operator == 'equals' && $field.val() == condition.if_value || condition.operator == 'not equals' && $field.val() != condition.if_value) {
66 if ($field.attr('type') == 'checkbox' && !$field.attr('checked')) continue;
67 $('#'+unit_tag+' #'+condition.then_field).show();
68 }
69
70
71 } else if ($field.length > 1) {
72
73 // multiple fields (tested with checkboxes, exclusive checkboxes, dropdown with multiple values)
74
75 var all_values = [];
76 var checked_values = [];
77 $field.each(function() {
78 all_values.push($(this).val());
79 if($(this).is(':checked')) {
80 checked_values.push($(this).val());
81 }
82 });
83
84 if (condition.operator == 'equals' && $.inArray(condition.if_value, checked_values) != -1) {
85 $('#'+unit_tag+' #'+condition.then_field).show();
86 } else if (condition.operator == 'not equals' && $.inArray(condition.if_value, all_values) != -1 && $.inArray(condition.if_value, checked_values) == -1) {
87 $('#'+unit_tag+' #'+condition.then_field).show();
88 }
89 }
90
91 }
92 }
93
94 for (var i = 0; i<options.length; i++) {
95 var unit_tag = options[i]['unit_tag'];
96 var conditions = options[i]['conditions'];
97 display_fields(unit_tag, conditions);
98 $('#'+unit_tag+' input, #'+unit_tag+' select, #'+unit_tag+' textarea').change({unit_tag:unit_tag, conditions:conditions}, function(e) {
99 display_fields(e.data.unit_tag, e.data.conditions);
100 });
101 }
102
103 });
104
105 })( jQuery );
106