Skip to content

gw-conditional-logic-operator-does-not-contain.php: Fixed rule value for does not contain rule. #1094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions gravity-forms/gw-conditional-logic-operator-does-not-contain.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Gravity Wiz // Gravity Forms // Conditional Logic Operator: "Does Not Contain"
*
*
* Instruction Video: https://www.loom.com/share/8e1b27ec47b341dbb4f0da2bec6a960b
*
* Check if a source field value does NOT contain a specific substring using the "does not contain" conditional logic operator.
Expand Down Expand Up @@ -42,9 +42,21 @@ public function output_admin_inline_script() {
}

gform.addFilter( 'gform_conditional_logic_operators', function( operators ) {
operators.does_not_contain = 'does not contain';
// Injects our "does_not_contain" operator directly below the "contains" operator for logical ordering.
operators = Object.fromEntries(
Object.entries(operators).flatMap(([k, v]) =>
k === "contains" ? [[k, v], ['does_not_contain', 'does not contain']] : [[k, v]]
)
);
return operators;
} );

let origRuleNeedsTextValue = window.ruleNeedsTextValue;
// Override the default GF function to add our custom operator.
window.ruleNeedsTextValue = function( rule ) {
let needsTextValue = origRuleNeedsTextValue( rule );
return needsTextValue || rule.operator.indexOf( 'does_not_contain' ) !== -1;
}
</script>
<?php
}
Expand Down Expand Up @@ -82,18 +94,21 @@ public function output_script() {
}

var fieldValue = '';
var $field = $( '#input_' + formId + '_' + rule.fieldId );

// Handle different field types
if ( $field.is(':checkbox') || $field.is(':radio') ) {
fieldValue = $field.filter(':checked').map(function() {
return this.value;
var $field = $( '#input_' + formId + '_' + rule.fieldId );
var $inputs = $field.find( 'input, select, textarea' );

// This is a quick-and-dirty way to get the value of the field. We may need to revisit for
// edge cases in the future.
if ( $inputs.is(':checkbox') || $inputs.is(':radio') ) {
fieldValue = $inputs.filter(':checked').map(function() {
return this.value;
}).get().join(',');
} else if ( $field.is('select[multiple]') ) {
fieldValue = $field.val() ? $field.val().join(',') : '';
} else if ( $inputs.is('select[multiple]') ) {
fieldValue = $inputs.val() ? $inputs.val().join(',') : '';
} else {
fieldValue = $field.val() || '';
}

isMatch = typeof fieldValue === 'string' && fieldValue.indexOf( rule.value ) === -1;

return isMatch;
Expand Down
Loading