Support Forum
Support › Meta Box Conditional Logic › TypeError: logics is undefinedResolved
Dear Anh,
I managed to reproduce the error by entering this code in a WYSIWYG field with a 'hidden' condition:
<header id="entry-header" class="entry__header yr-entry-header" data-rapid-sec="{"entry-header":"entry-header"}"></header>
Somehow this makes the value of the data-conditions attribute invalid JSON.
(It turned out one of my co-workers pasted this messy HTML from another site in a WYSIWYG-field, this is part of the HTML)
Hope this helps..?
Best,
AJ
Sorry, I am unable to paste my code as it's 20 post types, and thousands of custom fields.
But I was able to spot incorrect JSON in the data-conditions attribute which may help. It would seem that double quoted aren't getting encoded properly.
When I changed the get_conditional_html (and reverted the JS changes) I no longer see the logics errors.
esc_attr( htmlspecialchars( wp_json_encode( $conditions ), ENT_QUOTES, 'UTF-8' ) )
This was the json condition (part of it that didn't get encoded/escaped properly):
"desc": "Alphanumeric, no special characters except for " - ".",
Hope this helps.
Thanks a lot for your feedback! Looks like the json encode is the problem. I'll check and fix that.
Hey guys, can you help me to test the fix before releasing a new version? Please try changing parse_conditions
function to:
private function parse_conditions( $conditions ) {
$output = [];
if ( ! empty( $conditions['visible'] ) ) {
$output['visible'] = $this->parse_condition( $conditions['visible'] );
}
if ( ! empty( $conditions['hidden'] ) ) {
$output['hidden'] = $this->parse_condition( $conditions['hidden'] );
}
return $output;
}
The previous code does JSON-encode all field settings, which contains something like field description and value, which might break the JSON. The new code only encodes the conditions, which eliminate this issue and might improve the performance as well.
Thanks, I will test this today and report back.
Validated the updated function is working without issues.
Thank you!
I've released a new version for Meta Box Conditional Logic. The update for AIO will come next week.