Bug with select_advanced fields

Support MB Blocks Bug with select_advanced fields

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #47857
    digitaalitoimistodigitaalitoimisto
    Participant

    Hi, if I use select_advanced field on a MB block, and use multiple of this block on same page, only one of the blocks has working select2 functionality. This is due to all the inputs have same ID accross all the blocks.

    I managed to quickfix it like so:

    
    function dg_fix_metabox_select_advanced_gutenberg() {
        // Ladataan vain Gutenberg editorissa
        $screen = get_current_screen();
        if ( $screen && $screen->is_block_editor ) : ?>
        <script>
        (function($) {
            function forceMetaBoxSelectAdvanced($context) {
                console.log('Re-initializing Select2 in:', $context);
                $context.find('.rwmb-select_advanced').each(function() {
                    var $select = $(this);
                    var oldId = $select.attr('id');
    
                    // Varmista uniikki ID
                    var newId = 'dg-select2-' + Math.random().toString(36).substr(2, 9);
                    console.log('Rewriting ID:', oldId, '=>', newId);
                    $select.attr('id', newId);
    
                    // Varmista että optiot on olemassa
                    if (rwmb && rwmb.select2 && $select.data('options')) {
                        rwmb.select2.init($select);
                    }
                });
            }
    
            $(document).on('mb_ready', function(e) {
                setTimeout(function() {
                    forceMetaBoxSelectAdvanced($(document));
                }, 300);
            });
    
            $(document).on('mb_block_view_init', function(e, view) {
                setTimeout(function() {
                    forceMetaBoxSelectAdvanced(view.$el);
                }, 300);
            });
        })(jQuery);
    
        </script>
        <?php
        endif;
    }
    add_action( 'admin_footer', 'dg_fix_metabox_select_advanced_gutenberg' );
    

    Please consider having unique ID:s on the input fields on gutenberg blocks.

    #47877
    PeterPeter
    Moderator

    Hello,

    Thank you for your feedback and for sharing the solution.

    This issue has been escalated to the development team, we will work on this issue to fix it as soon as possible.

    Let me know if you have any questions.

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