Closed sjregan closed 3 years ago
I changed one of the textarea fields of the sample config to this:
array(
'id' => 'opt-textarea-no-html',
'type' => 'textarea',
'title' => esc_html__( 'Textarea Option - No HTML Validated', 'your-textdomain-here' ),
'subtitle' => esc_html__( 'All HTML will be stripped', 'your-textdomain-here' ),
'desc' => esc_html__( 'This is the description field, again good for additional info.', 'your-textdomain-here' ),
'validate_callback' => 'validate_json',
'default' => '{"opt-slider-label":"1", "opt-slider-text":"10"}',
),
And used this function (which I changed to use actual arrays instead of the short array syntax, which is legacy and not part of the WP Coding Standards).
function validate_json( $field, $value, $existing_value ) {
$json = json_decode( $value );
if ( json_last_error() === JSON_ERROR_NONE ) {
return array( 'value' => trim( $value ) );
}
$field['msg'] = esc_html__( 'You must enter valid JSON.', 'text-domain' );
return array(
'error' => $field,
'value' => trim( $existing_value ),
);
}
All worked as intended.
Save with bad JSON
Save with corrected JSON
The problem may lay within your execution. It does not appear to be Redux. Good luck!
Support Hash
https://support.redux.io/?id=yDWdaYTYRxDxPQglhZqGQ0HDgyezD78hUHJ0KylPK6nPQKD9GxbP%2FGGGkHSDxSCQ%2F8RAFZxGx5h8hWPZ2tr3ug%3D%3D
BTW Generate support hash URLs are 404s :)
Steps to reproduce
validate_callback
option.Expected Behavior
The validation error message to be removed.
Actual Behavior
The validation error message remains on screen even though the field has passed validation and been saved.
Any Error Details (PHP/JavaScript)
Example validation callback function: