Bug Report: Conditional Field Visibility in Redux Framework
Closed this issue · 2 comments
Site Health Report
Version | 4.4.18
Installation | plugin
Data directory | C:/xampp/htdocs/wp-content/plugins/redux-framework/redux-core/
Browser | Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0Browser: FirefoxVersion: 115.0Platform: Windows
Steps to reproduce
- Create a Redux section with fields, including those with IDs starting with "view".
- Set a condition for the "view" field to hide it when another field (x) is set to x1.
- Set "custom" field to "x2", and save.
- Reload the settings page.
Expected Behavior
Only the specific field matching the conditional logic should be hidden, while all other fields with IDs starting with "view" (including those in nested structures like repeaters) should remain visible.
The "view" field should be visible when "custom" field is set to x2 and should remain visible after reloading the page.
Actual Behavior
All fields with IDs starting with "view" are hidden, regardless of their individual conditions.
The "view" field is hidden upon reloading, even though it was filled and saved when "custom" field was set to x2.
Any Error Details (PHP/JavaScript)
- No JavaScript errors present in the console.
- No PHP errors logged.
Example Code:
$opt_name = 'test';
$args = array(
'opt_name' => $opt_name,
'dev_mode' => true,
);
Redux::set_args( $opt_name, $args );
Redux::setSection( $opt_name, array(
'title' => __( 'Theme Options', 'your-textdomain' ),
'id' => 'theme_options',
'fields' => array(
array(
'title' => __( 'field 1', 'your-textdomain' ),
'id' => 'view',
'type' => 'text',
),
array(
'title' => __( 'field 2', 'your-textdomain' ),
'id' => 'view2',
'type' => 'text',
),
array(
'title' => __( 'field 3', 'your-textdomain' ),
'id' => 'view_more_link',
'type' => 'text',
),
array(
'id' => 'items',
'type' => 'repeater',
'title' => __( 'field 4', 'your-textdomain' ),
'group_values' => true,
'bind_title' => 'heading',
'fields' => array(
array(
'id' => 'view_inner',
'type' => 'text',
'title' => __('field 5' , 'your-textdomain'),
),
array(
'id' => 'view',
'type' => 'text',
'title' => __('View' , 'your-textdomain'),
'required' => array('custom', '!=', 'x1')
),
array(
'id' => 'custom',
'type' => 'radio',
'title' => __( 'Custom' , 'your-textdomain' ),
'data' => array(
'x1' => 'x1',
'x2' => 'x2'
),
'default' => 'x2'
)
)
)
)
));
When repeater
group_values
is set to true, the behavior you describe will occur. If you intend to use the required
functionality in repeater,
it is recommended that you switch that option to false. Due to how the data is stored, it is not an issue that will not be fixed, and the grouped values features must remain for backward compatibility. Otherwise, I'd have gotten rid of it years ago.
See: https://devs.redux.io/core-extensions/repeater.html#the-group-values-argument
When
repeater
group_values
is set to true, the behavior you describe will occur. If you intend to use therequired
functionality inrepeater,
it is recommended that you switch that option to false. Due to how the data is stored, it is not an issue that will not be fixed, and the grouped values features must remain for backward compatibility. Otherwise, I'd have gotten rid of it years ago.See: https://devs.redux.io/core-extensions/repeater.html#the-group-values-argument
Thank You so much ♥