Conditional logic fails on switch in 1.6.6

Support MB Conditional Logic Conditional logic fails on switch in 1.6.6Resolved

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #15351
    FEDFED
    Participant

    Hello!

    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>
    #15359
    Anh TranAnh Tran
    Keymaster

    Hi FED,

    I've just tested 2 fields above and they work. Can you post the full code here?

    #15370
    FEDFED
    Participant

    That 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.

    https://pastebin.com/8JnPJYDh

    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!

    #15379
    Anh TranAnh Tran
    Keymaster

    Hi 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.

    #15385
    FEDFED
    Participant

    Thank 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.

    #15388
    FEDFED
    Participant

    The 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 );
            }
          }
    
    #15723
    udxudx
    Participant

    The same issue here.

    Uncaught TypeError: $scope.hasClass is not a function
        at conditional-logic.js?ver=1.5:240
    #15727
    Anh TranAnh Tran
    Keymaster

    Hey 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!

    #15870
    FEDFED
    Participant

    Works beautifully!

    Thanks!

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.