Conditional Fields for Contact Form 7 - Version 1.6.1

Version Description

(06-03-19) = * JS refactoring and small compatibility fix after code rewrite. * FREE: Added "Get PRO" button under Contact > Conditional Fields

Download this release

Release Info

Developer Jules Colle
Plugin Icon 128x128 Conditional Fields for Contact Form 7
Version 1.6.1
Comparing to
See all releases

Code changes from version 1.5.5 to 1.6.1

admin-style.css CHANGED
@@ -154,4 +154,8 @@
154
  flex: 1;
155
  margin-right: 3px !important; }
156
 
 
 
 
 
157
  /*# sourceMappingURL=admin-style.css.map */
154
  flex: 1;
155
  margin-right: 3px !important; }
156
 
157
+ .wpcf7cf-list li {
158
+ list-style: disc;
159
+ margin-left: 20px; }
160
+
161
  /*# sourceMappingURL=admin-style.css.map */
admin-style.css.map CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "version": 3,
3
- "mappings": "AAAA,kBAAmB;EAAE,OAAO,EAAE,YAAY;EAAE,OAAO,EAAC,IAAI;;AACxD,sBAAuB;EAAE,OAAO,EAAE,IAAI;;AACtC,sBAAuB;EAAE,KAAK,EAAE,IAAI;EAAE,MAAM,EAAE,KAAK;EAAE,WAAW,EAAE,iCAAiC;;AAEnG,0BAA2B;EAoHvB,UAAU,EAAE,IAAI;EAlHhB,yKAAyF;IACrF,OAAO,EAAE,IAAI;IACb,OAAO,EAAE,YAAY;IACrB,cAAc,EAAE,MAAM;IACtB,KAAK,EAAE,GAAG;EAEd,qDAA2B;IACvB,KAAK,EAAE,GAAG;EAEd,2DAAiC;IAC7B,KAAK,EAAE,GAAG;IACV,cAAc,EAAE,GAAG;EAIvB,2DAAiC;IAC7B,aAAa,EAAE,iBAAiB;IAChC,gBAAgB,EAAE,OAAO;IACzB,OAAO,EAAE,MAAM;EAGnB,yEAA+C;IAC3C,gBAAgB,EAAE,OAAO;EAG7B,qIAAgF;IAC5E,KAAK,EAAE,IAAI;EAGf,gDAAsB;IAClB,WAAW,EAAE,IAAI;EAGrB,6EAAmD;IAC/C,QAAQ,EAAE,QAAQ;EAGtB,mFA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B;IACjB,gBAAgB,EAAE,yBAAyB;EAI/C,sCAAY;IACR,OAAO,EAAC,IAAI;IACZ,KAAK,EAAE,IAAI;IACX,UAAU,EAAE,MAAM;EAEtB,oEAA0C;IACtC,OAAO,EAAE,YAAY;IACrB,cAAc,EAAE,GAAG;IACnB,MAAM,EAAE,IAAI;IACZ,QAAQ,EAAE,QAAQ;IAClB,WAAW,EAAE,IAAI;IACjB,KAAK,EAAE,IAAI;IACX,GAAG,EAAE,CAAC;EAGV,4CAAkB;IACd,aAAa,EAAE,GAAG;IAClB,MAAM,EAAE,IAAI;EAGhB,qGAAgD;IAC5C,MAAM,EAAE,QAAQ;EAKpB,2DAAiC;IAC7B,OAAO,EAAE,KAAK;IACd,QAAQ,EAAE,QAAQ;IAClB,KAAK,EAAE,IAAI;IACX,UAAU,EAAE,KAAK;IACjB,IAAI,EAAE,KAAK;EAGf,uEAA6C;IACzC,OAAO,EAAC,IAAI;EAGhB,mDAAyB;IACrB,SAAS,EAAE,KAAK;EAGpB,iCAAO;IACH,UAAU,EAAE,UAAU;IACtB,OAAO,EAAC,IAAI;EAGhB,6CAAmB;IACf,KAAK,EAAE,KAAK;EAGhB,6CAAmB;IACf,KAAK,EAAE,KAAK;EAIhB,oDAA0B;IACtB,IAAI,EAAC,CAAC;IACN,QAAQ,EAAC,QAAQ;EAGrB,4CAAkB;IACd,OAAO,EAAC,IAAI;EAEhB,kCAAQ;IACJ,KAAK,EAAE,IAAI;IACX,UAAU,EAAE,MAAM;EAGtB,oCAAU;IACN,gBAAgB;EAGpB,oCAAU;IACN,IAAI,EAAC,CAAC;IACN,YAAY,EAAC,cAAc;;AAInC,gBAAiB;EACb,UAAU,EAAE,IAAI;EAChB,WAAW,EAAE,IAAI",
4
  "sources": ["admin-style.scss"],
5
  "names": [],
6
  "file": "admin-style.css"
admin-style.scss CHANGED
@@ -214,3 +214,8 @@
214
  margin-right:3px !important;
215
  }
216
  }
 
 
 
 
 
214
  margin-right:3px !important;
215
  }
216
  }
217
+
218
+ .wpcf7cf-list li {
219
+ list-style: disc;
220
+ margin-left: 20px;
221
+ }
cf7cf.php CHANGED
@@ -35,7 +35,7 @@ class ContactForm7ConditionalFields {
35
 
36
  add_filter( 'wpcf7_validate', array($this, 'skip_validation_for_hidden_fields'), 2, 2 );
37
 
38
- // validation messages
39
  add_action('wpcf7_config_validator_validate', array($this,'wpcf7cf_config_validator_validate'));
40
 
41
 
@@ -48,6 +48,8 @@ class ContactForm7ConditionalFields {
48
  }
49
  }
50
 
 
 
51
  /**
52
  * Suppress invalid mailbox syntax errors on fields that contain existing conditional
53
  */
@@ -311,7 +313,7 @@ function wpcf7cf_properties($properties, $wpcf7form) {
311
 
312
  array_push($stack,$tag_html_type);
313
 
314
- echo '<'.$tag_html_type.' data-id="'.$tag_id.'" '.implode(' ',$tag_html_data).' data-class="wpcf7cf_group">';
315
  } else if ($form_part == '[/group]') {
316
  echo '</'.array_pop($stack).'>';
317
  } else {
35
 
36
  add_filter( 'wpcf7_validate', array($this, 'skip_validation_for_hidden_fields'), 2, 2 );
37
 
38
+ // validation messages
39
  add_action('wpcf7_config_validator_validate', array($this,'wpcf7cf_config_validator_validate'));
40
 
41
 
48
  }
49
  }
50
 
51
+
52
+
53
  /**
54
  * Suppress invalid mailbox syntax errors on fields that contain existing conditional
55
  */
313
 
314
  array_push($stack,$tag_html_type);
315
 
316
+ echo '<'.$tag_html_type.' data-id="'.$tag_id.'" data-orig_id="'.$tag_id.'" '.implode(' ',$tag_html_data).' data-class="wpcf7cf_group">';
317
  } else if ($form_part == '[/group]') {
318
  echo '</'.array_pop($stack).'>';
319
  } else {
contact-form-7-conditional-fields.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Contact Form 7 Conditional Fields
4
  Plugin URI: http://bdwm.be/
5
  Description: Adds support for conditional fields to Contact Form 7. This plugin depends on Contact Form 7.
6
  Author: Jules Colle
7
- Version: 1.5.5
8
  Author URI: http://bdwm.be/
9
  */
10
 
4
  Plugin URI: http://bdwm.be/
5
  Description: Adds support for conditional fields to Contact Form 7. This plugin depends on Contact Form 7.
6
  Author: Jules Colle
7
+ Version: 1.6.1
8
  Author URI: http://bdwm.be/
9
  */
10
 
init.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
 
3
- if (!defined('WPCF7CF_VERSION')) define( 'WPCF7CF_VERSION', '1.5.5' );
4
  if (!defined('WPCF7CF_REQUIRED_WP_VERSION')) define( 'WPCF7CF_REQUIRED_WP_VERSION', '4.1' );
5
  if (!defined('WPCF7CF_PLUGIN')) define( 'WPCF7CF_PLUGIN', __FILE__ );
6
  if (!defined('WPCF7CF_PLUGIN_BASENAME')) define( 'WPCF7CF_PLUGIN_BASENAME', plugin_basename( WPCF7CF_PLUGIN ) );
1
  <?php
2
 
3
+ if (!defined('WPCF7CF_VERSION')) define( 'WPCF7CF_VERSION', '1.6.1' );
4
  if (!defined('WPCF7CF_REQUIRED_WP_VERSION')) define( 'WPCF7CF_REQUIRED_WP_VERSION', '4.1' );
5
  if (!defined('WPCF7CF_PLUGIN')) define( 'WPCF7CF_PLUGIN', __FILE__ );
6
  if (!defined('WPCF7CF_PLUGIN_BASENAME')) define( 'WPCF7CF_PLUGIN_BASENAME', plugin_basename( WPCF7CF_PLUGIN ) );
js/scripts.js CHANGED
@@ -1,156 +1,223 @@
1
  var cf7signature_resized = 0; // for compatibility with contact-form-7-signature-addon
2
 
3
- var i=0;
4
- var timeout;
5
 
6
- var show_animation = { "height": "show", "marginTop": "show", "marginBottom": "show", "paddingTop": "show", "paddingBottom": "show" };
7
- var hide_animation = { "height": "hide", "marginTop": "hide", "marginBottom": "hide", "paddingTop": "hide", "paddingBottom": "hide" };
8
 
9
- var wpcf7cf = {
10
- initForm : function($form) {
11
 
12
- var $ = jQuery;
13
 
14
- var options_element = $form.find('input[name="_wpcf7cf_options"]').eq(0);
15
- if (options_element.length) {
16
- var value = options_element.val();
17
- if (value) {
18
 
19
- form_options = JSON.parse(value);
20
- form_options.unit_tag = $form.closest('.wpcf7').attr('id');
 
 
 
21
 
22
- var unit_tag = form_options['unit_tag'];
23
- var conditions = form_options['conditions'];
24
- var settings = form_options['settings'];
25
 
26
- settings.animation_intime = parseInt(settings.animation_intime);
27
- settings.animation_outtime = parseInt(settings.animation_outtime);
28
 
29
- if (settings.animation === 'no') {
30
- animation_intime = 0;
31
- animation_outtime = 0;
32
- }
 
33
 
34
- wpcf7cf.display_fields(unit_tag, conditions, settings);
 
 
35
 
36
- // monitor input changes, and call display_fields() is something has changed
37
- $('#'+unit_tag+' input, #'+unit_tag+' select, #'+unit_tag+' textarea, #'+unit_tag+' button').on('input paste change click',{unit_tag:unit_tag, conditions:conditions, settings:settings}, function(e) {
38
- clearTimeout(timeout);
39
- timeout = setTimeout(wpcf7cf.display_fields, 100, e.data.unit_tag, e.data.conditions, e.data.settings);
40
- });
41
 
42
- // bring form in initial state if the reset event is fired on it.
43
- $('#'+unit_tag+' form').on('reset', {unit_tag:unit_tag, conditions:conditions, settings:settings}, function(e) {
44
- setTimeout(wpcf7cf.display_fields, 200, e.data.unit_tag, e.data.conditions, e.data.settings);
45
- });
46
 
47
- }
48
- }
 
 
49
 
50
- //removed pro functions
51
- },
52
- display_fields : function(unit_tag, wpcf7cf_conditions, wpcf7cf_settings) {
53
 
54
- var $ = jQuery;
 
 
 
 
 
 
55
 
56
- $current_form = $('#'+unit_tag);
57
- $groups = $("[data-class='wpcf7cf_group']",$current_form);
58
 
59
- //for compatibility with contact-form-7-signature-addon
60
- if (cf7signature_resized == 0 && typeof signatures !== 'undefined' && signatures.constructor === Array && signatures.length > 0 ) {
61
- for (var i = 0; i < signatures.length; i++) {
62
- if (signatures[i].canvas.width == 0) {
63
 
64
- jQuery(".wpcf7-form-control-signature-body>canvas").eq(i).attr('width', jQuery(".wpcf7-form-control-signature-wrap").width());
65
- jQuery(".wpcf7-form-control-signature-body>canvas").eq(i).attr('height', jQuery(".wpcf7-form-control-signature-wrap").height());
66
 
67
- cf7signature_resized = 1;
68
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  }
70
  }
 
71
 
72
- $groups.addClass('wpcf7cf-hidden');
73
 
74
- for (var i=0; i < wpcf7cf_conditions.length; i++) {
75
 
76
- var condition = wpcf7cf_conditions[i];
77
 
78
- // compatibility with conditional forms created with older versions of the plugin ( < 1.4 )
79
- if (!('and_rules' in condition)) {
80
- condition.and_rules = [{'if_field':condition.if_field,'if_value':condition.if_value,'operator':condition.operator}];
81
- }
82
 
83
- var show_group = wpcf7cf.should_group_be_shown(condition, $current_form);
84
 
85
- if (show_group) {
86
- $('[data-id='+condition.then_field+']',$current_form).eq(0).removeClass('wpcf7cf-hidden');
87
- }
88
  }
 
89
 
90
- var animation_intime = wpcf7cf_settings.animation_intime;
91
- var animation_outtime = wpcf7cf_settings.animation_outtime;
92
-
93
- $groups.each(function (index) {
94
- $group = $(this);
95
- if ($group.is(':animated')) $group.finish(); // stop any current animations on the group
96
- if ($group.css('display') === 'none' && !$group.hasClass('wpcf7cf-hidden')) {
97
- if ($group.prop('tagName') === 'SPAN') {
98
- $group.show().trigger('wpcf7cf_show_group');
99
- } else {
100
- $group.animate(show_animation, animation_intime).trigger('wpcf7cf_show_group'); // show
101
- }
102
- } else if ($group.css('display') !== 'none' && $group.hasClass('wpcf7cf-hidden')) {
103
-
104
- if ($group.attr('data-clear_on_hide') !== undefined) {
105
- $inputs = $(':input', $group).not(':button, :submit, :reset, :hidden');
106
- $inputs.prop('checked', false).prop('selected', false).prop('selectedIndex', 0);
107
- $inputs.not('[type=checkbox],[type=radio],select').val('');
108
- $inputs.change();
109
- //display_fields();
110
- }
111
 
112
- if ($group.prop('tagName') === 'SPAN') {
113
- $group.hide().trigger('wpcf7cf_hide_group');
114
- } else {
115
- $group.animate(hide_animation, animation_outtime).trigger('wpcf7cf_hide_group'); // hide
116
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
117
 
 
 
 
 
118
  }
119
- });
120
 
121
- wpcf7cf.wpcf7cf_update_hidden_fields($current_form);
122
- },
123
- wpcf7cf_update_hidden_fields : function($form) {
124
 
125
- var $ = jQuery;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
 
127
- $hidden_group_fields = $form.find('[name="_wpcf7cf_hidden_group_fields"]');
128
- $hidden_groups = $form.find('[name="_wpcf7cf_hidden_groups"]');
129
- $visible_groups = $form.find('[name="_wpcf7cf_visible_groups"]');
130
- $repeaters = $form.find('[name="_wpcf7cf_repeaters"]');
131
-
132
- var hidden_fields = [];
133
- var hidden_groups = [];
134
- var visible_groups = [];
135
-
136
- $form.find('[data-class="wpcf7cf_group"]').each(function () {
137
- var $this = $(this);
138
- if ($this.hasClass('wpcf7cf-hidden')) {
139
- hidden_groups.push($this.data('id'));
140
- $this.find('input,select,textarea').each(function () {
141
- hidden_fields.push($(this).attr('name'));
142
- });
143
- } else {
144
- visible_groups.push($this.data('id'));
145
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
 
148
- $hidden_group_fields.val(JSON.stringify(hidden_fields));
149
- $hidden_groups.val(JSON.stringify(hidden_groups));
150
- $visible_groups.val(JSON.stringify(visible_groups));
151
 
152
- return true;
 
 
 
 
 
153
  },
 
154
  should_group_be_shown : function(condition, $current_form) {
155
 
156
  var $ = jQuery;
@@ -165,7 +232,7 @@ var wpcf7cf = {
165
 
166
  var regex_patt = new RegExp(condition_and_rule.if_value, 'i');
167
 
168
- $field = $('[name="' + condition_and_rule.if_field + '"], [name="' + condition_and_rule.if_field + '[]"], [data-original-name="' + condition_and_rule.if_field + '"], [data-original-name="' + condition_and_rule.if_field + '[]"]',$current_form); //, [data-original-name="' + condition_and_rule.if_field + '"]
169
 
170
  //TODO: ignore everything outside the sub_repeater if field is inside sub_repeater
171
 
@@ -180,7 +247,7 @@ var wpcf7cf = {
180
  }
181
 
182
  $field.find('option:selected').each(function () {
183
- var $option = $(this);
184
  option_val = $option.val()
185
  if (
186
  condition_and_rule.operator == 'equals' && option_val == condition_and_rule.if_value ||
@@ -237,14 +304,14 @@ var wpcf7cf = {
237
  var all_values = [];
238
  var checked_values = [];
239
  $field.each(function () {
240
- all_values.push($(this).val());
241
- if ($(this).is(':checked')) {
242
- checked_values.push($(this).val());
243
  }
244
  });
245
 
246
- var checked_value_index = $.inArray(condition_and_rule.if_value, checked_values);
247
- var value_index = $.inArray(condition_and_rule.if_value, all_values);
248
 
249
  if (
250
  ( condition_and_rule.operator == 'is empty' && checked_values.length == 0 ) ||
@@ -275,25 +342,21 @@ var wpcf7cf = {
275
 
276
  return show_group;
277
 
278
- },
279
- //removed pro functions
280
- };
281
 
 
282
 
283
 
284
- (function($) {
 
 
285
 
286
- $('.wpcf7-form').each(function(){
287
- wpcf7cf.initForm($(this));
 
 
 
 
288
  });
 
289
 
290
- // fix for exclusive checkboxes in IE (this will call the change-event again after all other checkboxes are unchecked, triggering the display_fields() function)
291
- var old_wpcf7ExclusiveCheckbox = $.fn.wpcf7ExclusiveCheckbox;
292
- $.fn.wpcf7ExclusiveCheckbox = function() {
293
- return this.find('input:checkbox').click(function() {
294
- var name = $(this).attr('name');
295
- $(this).closest('form').find('input:checkbox[name="' + name + '"]').not(this).prop('checked', false).eq(0).change();
296
- });
297
- };
298
-
299
- })( jQuery );
1
  var cf7signature_resized = 0; // for compatibility with contact-form-7-signature-addon
2
 
3
+ var wpcf7cf_timeout;
 
4
 
5
+ var wpcf7cf_show_animation = { "height": "show", "marginTop": "show", "marginBottom": "show", "paddingTop": "show", "paddingBottom": "show" };
6
+ var wpcf7cf_hide_animation = { "height": "hide", "marginTop": "hide", "marginBottom": "hide", "paddingTop": "hide", "paddingBottom": "hide" };
7
 
8
+ var wpcf7cf_change_events = 'input.wpcf7cf paste.wpcf7cf change.wpcf7cf click.wpcf7cf';
 
9
 
10
+ var wpcf7cf_forms = [];
11
 
12
+ function Wpcf7cfForm($form) {
 
 
 
13
 
14
+ var options_element = $form.find('input[name="_wpcf7cf_options"]').eq(0);
15
+ if (!options_element.length || !options_element.val()) {
16
+ // doesn't look like a CF7 form created with conditional fields plugin enabled.
17
+ return false;
18
+ }
19
 
20
+ var form = this;
 
 
21
 
22
+ var form_options = JSON.parse(options_element.val());
 
23
 
24
+ form.$form = $form;
25
+ form.$hidden_group_fields = $form.find('[name="_wpcf7cf_hidden_group_fields"]');
26
+ form.$hidden_groups = $form.find('[name="_wpcf7cf_hidden_groups"]');
27
+ form.$visible_groups = $form.find('[name="_wpcf7cf_visible_groups"]');
28
+ form.$repeaters = $form.find('[name="_wpcf7cf_repeaters"]');
29
 
30
+ form.unit_tag = $form.closest('.wpcf7').attr('id');
31
+ form.conditions = form_options['conditions'];
32
+ form.settings = form_options['settings'];
33
 
34
+ form.$groups = [];
35
+ form.repeaters = [];
36
+ form.steps = []; // comming soon (i hope)
37
+ form.fields = [];
 
38
 
39
+ form.settings.animation_intime = parseInt(form.settings.animation_intime);
40
+ form.settings.animation_outtime = parseInt(form.settings.animation_outtime);
 
 
41
 
42
+ if (form.settings.animation === 'no') {
43
+ form.settings.animation_intime = 0;
44
+ form.settings.animation_outtime = 0;
45
+ }
46
 
47
+ form.updateGroups();
48
+ form.updateEventListeners();
49
+ form.displayFields();
50
 
51
+ // bring form in initial state if the reset event is fired on it.
52
+ form.$form.on('reset', form, function(e) {
53
+ var form = e.data;
54
+ setTimeout(function(){
55
+ form.displayFields();
56
+ },200);
57
+ });
58
 
59
+ //removed pro functions
 
60
 
61
+ }
62
+ Wpcf7cfForm.prototype.displayFields = function() {
 
 
63
 
64
+ var form = this;
 
65
 
66
+ var unit_tag = this.unit_tag;
67
+ var wpcf7cf_conditions = this.conditions;
68
+ var wpcf7cf_settings = this.settings;
69
+
70
+ //for compatibility with contact-form-7-signature-addon
71
+ if (cf7signature_resized === 0 && typeof signatures !== 'undefined' && signatures.constructor === Array && signatures.length > 0 ) {
72
+ for (var i = 0; i < signatures.length; i++) {
73
+ if (signatures[i].canvas.width === 0) {
74
+
75
+ var $sig_canvas = jQuery(".wpcf7-form-control-signature-body>canvas");
76
+ var $sig_wrap = jQuery(".wpcf7-form-control-signature-wrap");
77
+ $sig_canvas.eq(i).attr('width', $sig_wrap.width());
78
+ $sig_canvas.eq(i).attr('height', $sig_wrap.height());
79
+
80
+ cf7signature_resized = 1;
81
  }
82
  }
83
+ }
84
 
85
+ form.$groups.addClass('wpcf7cf-hidden');
86
 
87
+ for (var i=0; i < wpcf7cf_conditions.length; i++) {
88
 
89
+ var condition = wpcf7cf_conditions[i];
90
 
91
+ // compatibility with conditional forms created with older versions of the plugin ( < 1.4 )
92
+ if (!('and_rules' in condition)) {
93
+ condition.and_rules = [{'if_field':condition.if_field,'if_value':condition.if_value,'operator':condition.operator}];
94
+ }
95
 
96
+ var show_group = wpcf7cf.should_group_be_shown(condition, form.$form);
97
 
98
+ if (show_group) {
99
+ jQuery('[data-id='+condition.then_field+']',form.$form).eq(0).removeClass('wpcf7cf-hidden');
 
100
  }
101
+ }
102
 
103
+ var animation_intime = wpcf7cf_settings.animation_intime;
104
+ var animation_outtime = wpcf7cf_settings.animation_outtime;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
 
106
+ form.$groups.each(function (index) {
107
+ $group = jQuery(this);
108
+ if ($group.is(':animated')) $group.finish(); // stop any current animations on the group
109
+ if ($group.css('display') === 'none' && !$group.hasClass('wpcf7cf-hidden')) {
110
+ if ($group.prop('tagName') === 'SPAN') {
111
+ $group.show().trigger('wpcf7cf_show_group');
112
+ } else {
113
+ $group.animate(wpcf7cf_show_animation, animation_intime).trigger('wpcf7cf_show_group'); // show
114
+ }
115
+ } else if ($group.css('display') !== 'none' && $group.hasClass('wpcf7cf-hidden')) {
116
+
117
+ if ($group.attr('data-clear_on_hide') !== undefined) {
118
+ $inputs = jQuery(':input', $group).not(':button, :submit, :reset, :hidden');
119
+ $inputs.prop('checked', false).prop('selected', false).prop('selectedIndex', 0);
120
+ $inputs.not('[type=checkbox],[type=radio],select').val('');
121
+ $inputs.change();
122
+ //display_fields();
123
+ }
124
 
125
+ if ($group.prop('tagName') === 'SPAN') {
126
+ $group.hide().trigger('wpcf7cf_hide_group');
127
+ } else {
128
+ $group.animate(wpcf7cf_hide_animation, animation_outtime).trigger('wpcf7cf_hide_group'); // hide
129
  }
 
130
 
131
+ }
132
+ });
 
133
 
134
+ form.updateHiddenFields();
135
+ }
136
+ Wpcf7cfForm.prototype.updateHiddenFields = function() {
137
+
138
+ var form = this;
139
+
140
+ var hidden_fields = [];
141
+ var hidden_groups = [];
142
+ var visible_groups = [];
143
+
144
+ form.$groups.each(function () {
145
+ var $this = jQuery(this);
146
+ if ($this.hasClass('wpcf7cf-hidden')) {
147
+ hidden_groups.push($this.data('id'));
148
+ $this.find('input,select,textarea').each(function () {
149
+ hidden_fields.push(jQuery(this).attr('name'));
150
+ });
151
+ } else {
152
+ visible_groups.push($this.data('id'));
153
+ }
154
+ });
155
 
156
+ form.hidden_fields = hidden_fields;
157
+ form.hidden_groups = hidden_groups;
158
+ form.visible_groups = visible_groups;
159
+
160
+ form.$hidden_group_fields.val(JSON.stringify(hidden_fields));
161
+ form.$hidden_groups.val(JSON.stringify(hidden_groups));
162
+ form.$visible_groups.val(JSON.stringify(visible_groups));
163
+
164
+ return true;
165
+ }
166
+ Wpcf7cfForm.prototype.updateGroups = function() {
167
+ var form = this;
168
+ form.$groups = form.$form.find('[data-class="wpcf7cf_group"]');
169
+
170
+ form.$subgroups = form.$form.find('.wpcf7cf_repeater_sub [data-class="wpcf7cf_group"]');
171
+
172
+ // var sub_conditions = [];
173
+
174
+ form.$subgroups.each(function() {
175
+ $group = jQuery(this);
176
+ var index = $group.data('repeater_index');
177
+ var group_name_orig = $group.data('orig_id');
178
+
179
+ form.conditions.forEach(function (condition) {
180
+ if (condition.then_field !== group_name_orig) return;
181
+ var and_rules = [];
182
+ condition.and_rules.forEach(function(entry) {
183
+ and_rules.push({if_field:entry.if_field+'__'+index, operator: entry.operator, if_value:entry.if_value});
184
+ });
185
+ form.conditions.push({
186
+ then_field:condition.then_field+'__'+index,
187
+ and_rules: and_rules
188
+ });
189
  });
190
+ });
191
+
192
+ }
193
+
194
+ Wpcf7cfForm.prototype.updateEventListeners = function() {
195
+
196
+ var form = this;
197
+
198
+ // monitor input changes, and call display_fields() if something has changed
199
+ jQuery('input, select, textarea, button',form.$form).not('.wpcf7cf_add, .wpcf7cf_remove').off(wpcf7cf_change_events).on(wpcf7cf_change_events,form, function(e) {
200
+ var form = e.data;
201
+ clearTimeout(wpcf7cf_timeout);
202
+ wpcf7cf_timeout = setTimeout(function() {
203
+ form.displayFields();
204
+ }, 100);
205
+ });
206
+
207
+ //removed pro functions
208
+ }
209
+
210
 
211
+ //removed pro functions
 
 
212
 
213
+
214
+ var wpcf7cf = {
215
+
216
+ // keep this for backwards compatibility
217
+ initForm : function($form) {
218
+ wpcf7cf_forms.push(new Wpcf7cfForm($form));
219
  },
220
+
221
  should_group_be_shown : function(condition, $current_form) {
222
 
223
  var $ = jQuery;
232
 
233
  var regex_patt = new RegExp(condition_and_rule.if_value, 'i');
234
 
235
+ $field = jQuery('[name="' + condition_and_rule.if_field + '"], [name="' + condition_and_rule.if_field + '[]"], [data-original-name="' + condition_and_rule.if_field + '"], [data-original-name="' + condition_and_rule.if_field + '[]"]',$current_form); //, [data-original-name="' + condition_and_rule.if_field + '"]
236
 
237
  //TODO: ignore everything outside the sub_repeater if field is inside sub_repeater
238
 
247
  }
248
 
249
  $field.find('option:selected').each(function () {
250
+ var $option = jQuery(this);
251
  option_val = $option.val()
252
  if (
253
  condition_and_rule.operator == 'equals' && option_val == condition_and_rule.if_value ||
304
  var all_values = [];
305
  var checked_values = [];
306
  $field.each(function () {
307
+ all_values.push(jQuery(this).val());
308
+ if (jQuery(this).is(':checked')) {
309
+ checked_values.push(jQuery(this).val());
310
  }
311
  });
312
 
313
+ var checked_value_index = jQuery.inArray(condition_and_rule.if_value, checked_values);
314
+ var value_index = jQuery.inArray(condition_and_rule.if_value, all_values);
315
 
316
  if (
317
  ( condition_and_rule.operator == 'is empty' && checked_values.length == 0 ) ||
342
 
343
  return show_group;
344
 
345
+ }
 
 
346
 
347
+ };
348
 
349
 
350
+ jQuery('.wpcf7-form').each(function(){
351
+ wpcf7cf_forms.push(new Wpcf7cfForm(jQuery(this)));
352
+ });
353
 
354
+ // fix for exclusive checkboxes in IE (this will call the change-event again after all other checkboxes are unchecked, triggering the display_fields() function)
355
+ var old_wpcf7ExclusiveCheckbox = jQuery.fn.wpcf7ExclusiveCheckbox;
356
+ jQuery.fn.wpcf7ExclusiveCheckbox = function() {
357
+ return this.find('input:checkbox').click(function() {
358
+ var name = jQuery(this).attr('name');
359
+ jQuery(this).closest('form').find('input:checkbox[name="' + name + '"]').not(this).prop('checked', false).eq(0).change();
360
  });
361
+ };
362
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -6,7 +6,7 @@ Website: http://bdwm.be
6
  Tags: wordpress, contact form 7, forms, conditional fields
7
  Requires at least: 4.1
8
  Tested up to: 5.2
9
- Stable tag: 1.5.5
10
  Requires PHP: 5.3
11
  License: GPLv2 or later
12
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -102,6 +102,15 @@ The conditional fields javascript code is loaded during wp_footer, so a call to
102
 
103
  == Changelog ==
104
 
 
 
 
 
 
 
 
 
 
105
  = 1.5.5 (05-20-19) =
106
  * Fixed and explained how to disable loading of the styles and scripts and only enable it on certain pages. More info: https://conditional-fields-cf7.bdwm.be/docs/faq/can-i-load-js-and-css-only-when-necessary/
107
  * Made sure default settings get set after activating plugin, without the need to visit the Contact > Conditional Fields page first.
6
  Tags: wordpress, contact form 7, forms, conditional fields
7
  Requires at least: 4.1
8
  Tested up to: 5.2
9
+ Stable tag: 1.6.1
10
  Requires PHP: 5.3
11
  License: GPLv2 or later
12
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
102
 
103
  == Changelog ==
104
 
105
+ = 1.6.1 (06-03-19) =
106
+ * JS refactoring and small compatibility fix after code rewrite.
107
+ * FREE: Added "Get PRO" button under Contact > Conditional Fields
108
+
109
+ = 1.6 (06-01-19) =
110
+ * JS code rewrite
111
+ * PRO: allow groups inside repeater
112
+ * PRO: make plugin ready for PRO release.
113
+
114
  = 1.5.5 (05-20-19) =
115
  * Fixed and explained how to disable loading of the styles and scripts and only enable it on certain pages. More info: https://conditional-fields-cf7.bdwm.be/docs/faq/can-i-load-js-and-css-only-when-necessary/
116
  * Made sure default settings get set after activating plugin, without the need to visit the Contact > Conditional Fields page first.
wpcf7cf-options.php CHANGED
@@ -115,6 +115,20 @@ function wpcf7cf_options_page() {
115
 
116
  submit_button();
117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  do_action('wpcf7cf_after_animation_settings');
119
 
120
  ?>
115
 
116
  submit_button();
117
 
118
+ if (!WPCF7CF_IS_PRO) {
119
+ ?>
120
+ <h3>Conditional Fields PRO</h3>
121
+ Get conditional Fields PRO to unlock the full potential of CF7
122
+ <ul class="wpcf7cf-list">
123
+ <li>Repeaters</li>
124
+ <li>Regular expressions</li>
125
+ <li>Togglebuttons</li>
126
+ <li>Additional operators <code>&lt;</code> <code>&gt;</code> <code>≤</code> <code>≥</code> <code>is empty</code></li>
127
+ <li>More comming soon (Multistep, Calculated Fields, ...)</li>
128
+ </ul>
129
+ <p><a target="_blank" class="button button-primary" href="https://conditional-fields-cf7.bdwm.be/contact-form-7-conditional-fields-pro/">Get PRO</a></p>
130
+ <?php
131
+ }
132
  do_action('wpcf7cf_after_animation_settings');
133
 
134
  ?>