Conditional Fields for Contact Form 7 - Version 0.1.1

Version Description

Fixed bug with exclusive checkboxes (https://wordpress.org/support/topic/groups-not-showing)

Download this release

Release Info

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

Code changes from version 0.1 to 0.1.1

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: 0.1
8
  Author URI: http://bdwm.be/
9
  */
10
 
@@ -26,7 +26,7 @@ Author URI: http://bdwm.be/
26
  ?>
27
  <?php
28
 
29
- define( 'WPCF7CF_VERSION', '0.1' );
30
  define( 'WPCF7CF_REQUIRED_WP_VERSION', '4.1' );
31
  define( 'WPCF7CF_PLUGIN', __FILE__ );
32
  define( 'WPCF7CF_PLUGIN_BASENAME', plugin_basename( WPCF7CF_PLUGIN ) );
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: 0.1.1
8
  Author URI: http://bdwm.be/
9
  */
10
 
26
  ?>
27
  <?php
28
 
29
+ define( 'WPCF7CF_VERSION', '0.1.1' );
30
  define( 'WPCF7CF_REQUIRED_WP_VERSION', '4.1' );
31
  define( 'WPCF7CF_PLUGIN', __FILE__ );
32
  define( 'WPCF7CF_PLUGIN_BASENAME', plugin_basename( WPCF7CF_PLUGIN ) );
js/scripts.js CHANGED
@@ -12,36 +12,30 @@ $(document).ready(function() {
12
  console.log(condition);
13
  if (condition.then_visibility == 'hide') continue;
14
 
15
- if ($('[name='+condition.if_field+']').length) {
16
 
17
- // single field
 
 
18
 
19
- $field = $('[name='+condition.if_field+']');
20
  if (condition.operator == 'equals' && $field.val() == condition.if_value || condition.operator == 'not equals' && $field.val() != condition.if_value) {
 
21
  $('#'+condition.then_field).show();
22
  }
23
 
24
- } else if ($('[name='+condition.if_field+'\\[\\]]').length) {
25
-
26
- // multiple fields (checkboxes)
27
 
28
- $fields = $('[name='+condition.if_field+'\\[\\]]');
29
 
30
  var all_values = [];
31
  var checked_values = [];
32
- $fields.each(function() {
33
  all_values.push($(this).val());
34
  if($(this).is(':checked')) {
35
  checked_values.push($(this).val());
36
  }
37
  });
38
 
39
- console.log(all_values);
40
- console.log(checked_values);
41
- console.log(condition.operator);
42
- console.log(condition.if_value);
43
- console.log(condition.then_field);
44
-
45
  if (condition.operator == 'equals' && $.inArray(condition.if_value, checked_values) != -1) {
46
  $('#'+condition.then_field).show();
47
  } else if (condition.operator == 'not equals' && $.inArray(condition.if_value, all_values) != -1 && $.inArray(condition.if_value, checked_values) == -1) {
12
  console.log(condition);
13
  if (condition.then_visibility == 'hide') continue;
14
 
15
+ $field = $('[name='+condition.if_field+']').length ? $('[name='+condition.if_field+']') : $('[name='+condition.if_field+'\\[\\]]');
16
 
17
+ if ($field.length == 1) {
18
+
19
+ // single field (tested with text field, single checkbox)
20
 
 
21
  if (condition.operator == 'equals' && $field.val() == condition.if_value || condition.operator == 'not equals' && $field.val() != condition.if_value) {
22
+ if ($field.attr('type') == 'checkbox' && !$field.attr('checked')) continue;
23
  $('#'+condition.then_field).show();
24
  }
25
 
26
+ } else if ($field.length > 1) {
 
 
27
 
28
+ // multiple fields (tested with checkboxes, exclusive checkboxes)
29
 
30
  var all_values = [];
31
  var checked_values = [];
32
+ $field.each(function() {
33
  all_values.push($(this).val());
34
  if($(this).is(':checked')) {
35
  checked_values.push($(this).val());
36
  }
37
  });
38
 
 
 
 
 
 
 
39
  if (condition.operator == 'equals' && $.inArray(condition.if_value, checked_values) != -1) {
40
  $('#'+condition.then_field).show();
41
  } else if (condition.operator == 'not equals' && $.inArray(condition.if_value, all_values) != -1 && $.inArray(condition.if_value, checked_values) == -1) {
readme.txt CHANGED
@@ -5,16 +5,19 @@ Website: http://bdwm.be
5
  Tags: wordpress, contact form 7, forms, conditional fields
6
  Requires at least: 3.6.1
7
  Tested up to: 4.5.2
8
- Stable tag: 0.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
12
  Adds support for conditional fields to Contact Form 7.
13
- This plugin depends on Contact Form 7.
14
 
15
  == Description ==
16
 
17
- Adds conditional fields support to [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
 
 
 
 
18
 
19
  == Installation ==
20
 
@@ -36,3 +39,7 @@ Because no questions have been asked frequently about this plugin.
36
  = 0.1 =
37
 
38
  First release
 
 
 
 
5
  Tags: wordpress, contact form 7, forms, conditional fields
6
  Requires at least: 3.6.1
7
  Tested up to: 4.5.2
8
+ Stable tag: 0.1.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
12
  Adds support for conditional fields to Contact Form 7.
 
13
 
14
  == Description ==
15
 
16
+ This plugin adds conditional logic to [Contact Form 7](https://wordpress.org/plugins/contact-form-7/).
17
+
18
+ If you edit your CF7 form, you will see an additional tag called "Conditional fields Group". Everything you put between the start and end tag will be hidden by default.
19
+ After you added the field group(s), you should click Save.
20
+ Then you should go to the "Conditional fields" tab to create one or more conditions that will make the group(s) appear.
21
 
22
  == Installation ==
23
 
39
  = 0.1 =
40
 
41
  First release
42
+
43
+ = 0.1.1 =
44
+
45
+ Fixed bug with exclusive checkboxes (https://wordpress.org/support/topic/groups-not-showing)