Add “not contains” logic for conditional fields support
-
Hey,
for excluding several things likehide if IBAN "not contains" DEIt would be awesome to have this feature
from um-filters-fields.php and “Validate conditional logic” section I’ve tried to adapt the contains condition to match the not contains condition
if ( isset( $_POST[ $condition_metakey ] ) ) { $cond_value = ( $fields[ $value[1] ]['type'] === 'radio' ) ? $_POST[ $condition_metakey ][0] : $_POST[ $condition_metakey ]; list( $visibility, $parent_key, $op, $parent_value ) = $value; if ( $visibility == 'hide' ) { if ( $op == 'empty' ) { if ( empty( $cond_value ) ) { $array['required'] = 0; } } elseif ( $op == 'not empty' ) { if ( ! empty( $cond_value ) ) { $array['required'] = 0; } } elseif ( $op == 'equals to' ) { if ( $cond_value == $parent_value ) { $array['required'] = 0; } } elseif ( $op == 'not equals' ) { if ( $cond_value != $parent_value ) { $array['required'] = 0; } } elseif ( $op == 'greater than' ) { if ( $cond_value > $parent_value ) { $array['required'] = 0; } } elseif ( $op == 'less than' ) { if ( $cond_value < $parent_value ) { $array['required'] = 0; } } elseif ( $op == 'contains' ) { if ( is_string( $cond_value ) && strstr( $cond_value, $parent_value ) ) { $array['required'] = 0; } if( is_array( $cond_value ) && in_array( $parent_value, $cond_value ) ) { $array['required'] = 0; } } // Add a new condition for "not contains" elseif ( $op == 'not contains' ) { if ( is_string( $cond_value ) && ! strstr( $cond_value, $parent_value ) ) { $array['required'] = 0; } if( is_array( $cond_value ) && ! in_array( $parent_value, $cond_value ) ) { $array['required'] = 0; } } } elseif ( $visibility == 'show' ) { if ( $op == 'empty' ) { if ( ! empty( $cond_value ) ) { $array['required'] = 0; } } elseif ( $op == 'not empty' ) { if ( empty( $cond_value ) ) { $array['required'] = 0; } } elseif ( $op == 'equals to' ) { if ( $cond_value != $parent_value ) { $array['required'] = 0; } } elseif ( $op == 'not equals' ) { if ( $cond_value == $parent_value ) { $array['required'] = 0; } } elseif ( $op == 'greater than' ) { if ( $cond_value <= $parent_value ) { $array['required'] = 0; } } elseif ( $op == 'less than' ) { if ( $cond_value >= $parent_value ) { $array['required'] = 0; } } elseif ( $op == 'contains' ) { if( is_string( $cond_value ) && !strstr( $cond_value, $parent_value ) ) { $array['required'] = 0; } if( is_array( $cond_value ) && !in_array( $parent_value, $cond_value ) ) { $array['required'] = 0; } } // Add a new condition for "not contains" elseif ( $op == 'not contains' ) { if( is_string( $cond_value ) && strstr( $cond_value, $parent_value ) ) { $array['required'] = 0; } if( is_array( $cond_value ) && in_array( $parent_value, $cond_value ) ) { $array['required'] = 0; } } } }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Add “not contains” logic for conditional fields support’ is closed to new replies.