Home Forums Gutenberg block script backend render problem


block script backend render problem

  • Hi

    I’m trying to render my Block JS in the backend.
    I made hide and show elements in JS with custom checkbox icon (switcher)

    This is my code :

    			'name' => 'formulaires-documentayion',
    			'title' => 'Formulaires documentation',
    			'description' => 'Formulaires documentation',
    			'icon' => 'list-view',
    			'keywords' => array('documentation, formulaire, documents, formulaires, mycat'),
    			'mode' => 'preview',
    			'category'          => 'mycat',
    			'enqueue_assets'    => function() {
    				wp_enqueue_style( 'formulaires-documentaion', get_stylesheet_directory_uri() . '/assets/blocks/formulaires-documentaion/formulaires-documentaion.css' );
    				wp_enqueue_script( 'formulaires-documentaion', get_stylesheet_directory_uri() . '/assets/blocks/formulaires-documentaion/formulaires-documentaion.js', array('jquery'), '', true );

    and the JS

        var initializeBlock = function( $block ) {
            $('<div class="ico"></div>').prependTo('.switcher .checkbox label');
            $('<div class="checkcolored"></div>').prependTo('.coloredcheckbox .checkbox label');
            $(".coloredcheckbox .checkbox input[type=checkbox]").change(function(){
            $(".switcher .checkbox input[type=checkbox]").change(function(){
     // Initialize dynamic block preview (editor).
     if( window.acf ) {
        window.acf.addAction( 'render_block_preview/type=formulaires-documentaion', initializeBlock );

    This is render in backend but it’s seems it’s loading multple time because it’s generating multiple <div class=”ico”>. But only in backend

    Have you an idea what I did wrong ?

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.