TypeError: logics is undefined
Support › MB Conditional Logic › TypeError: logics is undefinedResolved
- This topic has 21 replies, 6 voices, and was last updated 5 years, 6 months ago by
Anh Tran.
-
AuthorPosts
-
April 28, 2020 at 3:58 PM #19335
Aart Jan van der Linden
ParticipantDear 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
April 28, 2020 at 9:53 PM #19343Austin Passy
ParticipantSorry, 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.
April 29, 2020 at 10:38 AM #19357Anh Tran
KeymasterThanks a lot for your feedback! Looks like the json encode is the problem. I'll check and fix that.
April 29, 2020 at 11:19 AM #19360Anh Tran
KeymasterHey guys, can you help me to test the fix before releasing a new version? Please try changing
parse_conditionsfunction 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.
April 29, 2020 at 10:20 PM #19377Austin Passy
ParticipantThanks, I will test this today and report back.
April 30, 2020 at 12:08 AM #19380Austin Passy
ParticipantValidated the updated function is working without issues.
April 30, 2020 at 9:57 AM #19387Anh Tran
KeymasterThank you!
I've released a new version for MB Conditional Logic. The update for AIO will come next week.
-
AuthorPosts
- You must be logged in to reply to this topic.