Skip to content

Commit 3957cb6

Browse files
gw-conditional-logic-operator-does-not-contain.php: Updated rule input to use a text input when does not contain operator is selected.
* `gw-conditional-logic-operator-does-not-contain.php`: Fixed rule value for `does not contain` rule. * `gw-conditional-logic-operator-does-not-contain.php`: Fixed rule value for `does not contain` rule. * `gw-conditional-logic-operator-does-not-contain.php`: Fixed rule value for `does not contain` rule. * ~ Improvements. --------- Co-authored-by: David Smith <[email protected]>
1 parent 015475d commit 3957cb6

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

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

+25-10
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,9 +42,21 @@ 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
} );
53+
54+
let origRuleNeedsTextValue = window.ruleNeedsTextValue;
55+
// Override the default GF function to add our custom operator.
56+
window.ruleNeedsTextValue = function( rule ) {
57+
let needsTextValue = origRuleNeedsTextValue( rule );
58+
return needsTextValue || rule.operator.indexOf( 'does_not_contain' ) !== -1;
59+
}
4860
</script>
4961
<?php
5062
}
@@ -82,18 +94,21 @@ public function output_script() {
8294
}
8395

8496
var fieldValue = '';
85-
var $field = $( '#input_' + formId + '_' + rule.fieldId );
86-
87-
// Handle different field types
88-
if ( $field.is(':checkbox') || $field.is(':radio') ) {
89-
fieldValue = $field.filter(':checked').map(function() {
90-
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;
91105
}).get().join(',');
92-
} else if ( $field.is('select[multiple]') ) {
93-
fieldValue = $field.val() ? $field.val().join(',') : '';
106+
} else if ( $inputs.is('select[multiple]') ) {
107+
fieldValue = $inputs.val() ? $inputs.val().join(',') : '';
94108
} else {
95109
fieldValue = $field.val() || '';
96110
}
111+
97112
isMatch = typeof fieldValue === 'string' && fieldValue.indexOf( rule.value ) === -1;
98113

99114
return isMatch;

0 commit comments

Comments
 (0)