Conditional logic fails on switch in 1.6.6
Support › MB Conditional Logic › Conditional logic fails on switch in 1.6.6Resolved
- This topic has 8 replies, 3 voices, and was last updated 5 years, 8 months ago by
FED.
-
AuthorPosts
-
July 15, 2019 at 10:49 PM #15351
FED
ParticipantHello!
Since updating to 1.6.6, all of the switches I'm using to toggle metaboxes on/off aren't working. After I save the page, the sections will appear/disappear properly, so the field is getting added to the DB correctly.
Here's a sample of the code I'm using and the JavaScript error I get in the admin.
My code:array( 'name' => 'Add modal information?', 'id' => 'service_payment_info_select', 'type' => 'switch', 'on_label' => 'Yes', 'off_label' =>'No' ), array( 'visible' => array('service_payment_info_select', true), 'id' => 'service_modal_info_link_text', 'name' => 'Clickable link text', 'type' => 'text', ),
JS error:
conditional-logic.js?ver=1.5:240 Uncaught TypeError: $scope.hasClass is not a function at conditional-logic.js?ver=1.5:240 at Array.forEach (<anonymous>) at isLogicCorrect (conditional-logic.js?ver=1.5:224) at conditional-logic.js?ver=1.5:205 at Function.s.each.s.forEach (underscore.min.js?ver=1.8.3:1) at conditional-logic.js?ver=1.5:198 at Function.s.each.s.forEach (underscore.min.js?ver=1.8.3:1) at runConditionalLogic (conditional-logic.js?ver=1.5:197) at init (conditional-logic.js?ver=1.5:563) at conditional-logic.js?ver=1.5:571<code></code>
July 16, 2019 at 2:40 PM #15359Anh Tran
KeymasterHi FED,
I've just tested 2 fields above and they work. Can you post the full code here?
July 16, 2019 at 11:18 PM #15370FED
ParticipantThat is a small piece of a MUCH larger and more complex set of metaboxes, with custom classes in some cases. Here's most of the relevant code.
I rolled back to 1.6.4 and the JS error disappears and the metaboxes work as expected. I haven't tried 1.6.5 yet.
Thanks!
July 17, 2019 at 11:32 AM #15379Anh Tran
KeymasterHi FED,
Here is the video I recorded with your code:
https://www.loom.com/share/2c4fe91c390c4faab2a638454a06df90
As you see, the switch field works. I tested with Gutenberg (WordPress 5.2.2) and also tested with the classic editor (with Disable Gutenberg plugin activated). There's also no errors in the console.
July 17, 2019 at 9:03 PM #15385FED
ParticipantThank you for looking into this!
This is weird. I'm using the Disable Guttenberg plugin and that's where I'm seeing the issue. When I use Guttenberg, I don't see the problem. I'll try and figure out what's going on. It might be something custom I'm doing.
July 18, 2019 at 1:56 AM #15388FED
ParticipantThe other thing I'm noticing is that I'm always seeing the JS error in the admin with Disable Gutenberg turned on, even if I'm on an admin page without any meta boxes.
I was able to address the JS error and the switch meta box not working by wrapping the block starting at line 240 with a check to make sure
$scope
is defined.if ( window.hasOwnProperty.$scope ) { // Try broader scope if field is in a cloneable group. if ( ! isGutenbergElement( logic[0] ) && ! dependentFieldSelector && $scope.hasClass( 'rwmb-group-clone' ) ) { $scope = getScope( $field, true ); selectorCache = getSelectorCache( $scope ), dependentFieldSelector = getSelector( logic[0], selectorCache ); } }
August 16, 2019 at 9:44 PM #15723udx
ParticipantThe same issue here.
Uncaught TypeError: $scope.hasClass is not a function at conditional-logic.js?ver=1.5:240
August 17, 2019 at 2:09 PM #15727Anh Tran
KeymasterHey guys,
Thanks for your feedback. Based on what FED offered, I think this patch is a little better. Can you please try replace the line 240 in the
conditional-logic.js
with this?if ( ! isGutenbergElement( logic[0] ) && ! dependentFieldSelector && $scope && $scope.hasClass( 'rwmb-group-clone' ) ) {
I'll release a new version when it's confirmed. Thanks!
August 26, 2019 at 10:49 PM #15870FED
ParticipantWorks beautifully!
Thanks!
-
AuthorPosts
- You must be logged in to reply to this topic.