From 8ef65eaa3712029cc6fe696e4f1a2eb84c0dfa7f Mon Sep 17 00:00:00 2001 From: Saif Sultan Date: Mon, 14 Apr 2025 13:24:59 +0530 Subject: [PATCH 1/2] `gw-conditional-logic-operator-does-not-contain.php`: Added snippet for does not contain conditional logic comparison. --- ...tional-logic-operator-does-not-contain.php | 160 ++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 gravity-forms/gw-conditional-logic-operator-does-not-contain.php diff --git a/gravity-forms/gw-conditional-logic-operator-does-not-contain.php b/gravity-forms/gw-conditional-logic-operator-does-not-contain.php new file mode 100644 index 000000000..a662f2cd4 --- /dev/null +++ b/gravity-forms/gw-conditional-logic-operator-does-not-contain.php @@ -0,0 +1,160 @@ + + + is_applicable_form( $form ) && ! has_action( 'wp_footer', array( $this, 'output_script' ) ) ) { + add_action( 'wp_footer', array( $this, 'output_script' ) ); + add_action( 'gform_preview_footer', array( $this, 'output_script' ) ); + } + + return $form; + } + + public function output_script() { + ?> + + is_applicable_form( $form ) ) { + return; + } + + $script = 'new GWCLODoesNotContain();'; + $slug = implode( '_', array( 'gwclo_does_not_contain', $form['id'] ) ); + + GFFormDisplay::add_init_script( $form['id'], $slug, GFFormDisplay::ON_PAGE_RENDER, $script ); + } + + public function whitelist_operator( $is_valid, $operator ) { + if ( $operator === 'does_not_contain' ) { + $is_valid = true; + } + return $is_valid; + } + + public function evaluate_operator( $is_match, $field_value, $target_value, $operation, $source_field, $rule ) { + + if ( $rule['operator'] !== 'does_not_contain' || rgar( $rule, 'gwclodncEvaluatingOperator' ) ) { + return $is_match; + } + + $rule['gwclodncEvaluatingOperator'] = true; + + // If the field contains the target value, it's not a match. + $is_match = strpos( $field_value, $target_value ) === false; + + $rule['gwclodncEvaluatingOperator'] = false; + + return $is_match; + } + + public function convert_conditional_logic_to_field_filters( $field_filters ) { + + foreach ( $field_filters as &$field_filter ) { + if ( ! is_array( $field_filter ) ) { + continue; + } + + switch ( $field_filter['operator'] ) { + case 'does_not_contain': + $field_filter['operator'] = 'NOT LIKE'; + $field_filter['value'] = '%' . $field_filter['value'] . '%'; + break; + } + } + + return $field_filters; + } + + public function is_applicable_form( $form ) { + return GFFormDisplay::has_conditional_logic( $form ); + } +} + +# Configuration + +new GF_CLO_Does_Not_Contain(); From c6f05f88db28cb72b08047368a5e313094a1bf82 Mon Sep 17 00:00:00 2001 From: saifsultanc Date: Wed, 30 Apr 2025 11:47:51 +0530 Subject: [PATCH 2/2] `gw-conditional-logic-operator-does-not-contain.php`: Added snippet for does not contain conditional logic comparison. --- ...nditional-logic-operator-does-not-contain.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/gravity-forms/gw-conditional-logic-operator-does-not-contain.php b/gravity-forms/gw-conditional-logic-operator-does-not-contain.php index a662f2cd4..f96ddbdc5 100644 --- a/gravity-forms/gw-conditional-logic-operator-does-not-contain.php +++ b/gravity-forms/gw-conditional-logic-operator-does-not-contain.php @@ -81,8 +81,20 @@ public function output_script() { return isMatch; } - var fieldValue = $( '#input_' + formId + '_' + rule.fieldId ).val(); - isMatch = fieldValue.indexOf( rule.value ) === -1; + 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; + }).get().join(','); + } else if ( $field.is('select[multiple]') ) { + fieldValue = $field.val() ? $field.val().join(',') : ''; + } else { + fieldValue = $field.val() || ''; + } + isMatch = typeof fieldValue === 'string' && fieldValue.indexOf( rule.value ) === -1; return isMatch; } );