Skip to content

Commit 034102a

Browse files
committed
~ Improvements.
1 parent 348da97 commit 034102a

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

gravity-forms/gw-conditional-logic-operator-does-not-contain.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* Gravity Wiz // Gravity Forms // Conditional Logic Operator: "Does Not Contain"
4-
*
4+
*
55
* Instruction Video: https://www.loom.com/share/8e1b27ec47b341dbb4f0da2bec6a960b
66
*
77
* Check if a source field value does NOT contain a specific substring using the "does not contain" conditional logic operator.
@@ -42,13 +42,18 @@ public function output_admin_inline_script() {
4242
}
4343

4444
gform.addFilter( 'gform_conditional_logic_operators', function( operators ) {
45-
operators.does_not_contain = 'does not contain';
45+
// Injects our "does_not_contain" operator directly below the "contains" operator for logical ordering.
46+
operators = Object.fromEntries(
47+
Object.entries(operators).flatMap(([k, v]) =>
48+
k === "contains" ? [[k, v], ['does_not_contain', 'does not contain']] : [[k, v]]
49+
)
50+
);
4651
return operators;
4752
} );
4853

4954
let origRuleNeedsTextValue = window.ruleNeedsTextValue;
5055
// Override the default GF function to add our custom operator.
51-
function ruleNeedsTextValue( rule ) {
56+
window.ruleNeedsTextValue = function( rule ) {
5257
let needsTextValue = origRuleNeedsTextValue( rule );
5358
return needsTextValue || rule.operator.indexOf( 'does_not_contain' ) !== -1;
5459
}
@@ -89,18 +94,21 @@ public function output_script() {
8994
}
9095

9196
var fieldValue = '';
92-
var $field = $( '#input_' + formId + '_' + rule.fieldId );
93-
94-
// Handle different field types
95-
if ( $field.is(':checkbox') || $field.is(':radio') ) {
96-
fieldValue = $field.filter(':checked').map(function() {
97-
return this.value;
97+
var $field = $( '#input_' + formId + '_' + rule.fieldId );
98+
var $inputs = $field.find( 'input, select, textarea' );
99+
100+
// This is a quick-and-dirty way to get the value of the field. We may need to revisit for
101+
// edge cases in the future.
102+
if ( $inputs.is(':checkbox') || $inputs.is(':radio') ) {
103+
fieldValue = $inputs.filter(':checked').map(function() {
104+
return this.value;
98105
}).get().join(',');
99-
} else if ( $field.is('select[multiple]') ) {
100-
fieldValue = $field.val() ? $field.val().join(',') : '';
106+
} else if ( $inputs.is('select[multiple]') ) {
107+
fieldValue = $inputs.val() ? $inputs.val().join(',') : '';
101108
} else {
102109
fieldValue = $field.val() || '';
103110
}
111+
104112
isMatch = typeof fieldValue === 'string' && fieldValue.indexOf( rule.value ) === -1;
105113

106114
return isMatch;

0 commit comments

Comments
 (0)