• Resolved wlaedimir

    (@wlaedimir)


    Hi,

    I’m using CMB2 to create some custom metaboxes for my page generator backend. This metaboxes are made as a group field, so inside of this group field I placed a text type input, with the attribute of ‘repeatable’ for having repeatable text boxes.

    So the problem is, that everytime that I do click on “Add Row” nothing happens.. But, when I click on “Delete Row” one row dissapears, but if do click on “Add Row” again, after I erased one row nothing happens

    I’ve just realized that when I save the changes in the page, another row appears, but not when I do click on the add row button.

    https://wordpress.org/plugins/cmb2/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Sounds like it could potentially be a js issue going on on the screen you’re trying these in. Are you familiar with your browser’s developer tools at all? specifically the js console? I’d refresh the page with the console open and try adding/removing again, while noting down any errors showing up in the console, if any.

    Thread Starter wlaedimir

    (@wlaedimir)

    the console says

    TypeError: $self.data(...) is undefined

    everytime I press the “Add Row” button.

    And there’s another thing, how can I call those repeatable text on the template? Do I have to do another foreach to call the inner repeatable?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I’d need to see the resulting saved data to confirm how many loops you may need, but offhand, I assume that may be the case.

    Could you share the code you’re using for the metaboxes? We do have $self.data() references in our JS, so it should be theoretically possible that I could either see what’s going wrong or recreate and debug further that way.

    Thread Starter wlaedimir

    (@wlaedimir)

    yeah, this is the code Michael

    $meta_boxes['field_group'] = array(
            'id'         => 'nodos_automaticos',
            'title'      => __( 'Nodos', 'gobcl' ),
            'pages'      => array( 'page', ),
            'cmb_styles' => true,
            'fields'     => array(
                array(
                    'id'          => $prefix . 'nodos_auto',
                    'type'        => 'group',
                    'description' => __( 'Creación simple de nodos de contenido', 'gobcl' ),
                    'options'     => array(
                        'group_title'   => __( 'Nodo N°{#}', 'gobcl' ), // {#} gets replaced by row number
                        'add_button'    => __( 'Añadir otro nodo', 'gobcl' ),
                        'remove_button' => __( 'Quitar nodo', 'gobcl' ),
                        'sortable'      => true, // beta
                    ),
                    // Fields array works the same, except id's only need to be unique for this group. Prefix is not needed.
                    'fields'      => array(
                        array(
                            'name' => 'Titulo de Nodo',
                            'id'   => 'title',
                            'type' => 'text',
                            // 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types)
                        ),
                        array(
                            'name' => 'Descripción o Párrafo para nodo',
                            'description' => 'Escriba una descripción para el contenido de este nodo',
                            'id'   => 'description',
                            'type' => 'textarea_small',
                        ),
                        array(
                            'name' => 'Imagen de cabecera de nodo',
                            'description' => 'Añada una imagen para la cabecera del nodo',
                            'id'   => 'image',
                            'type' => 'file',
                        ),
                        array(
                            'name' => 'Subtítulo para foto',
                            'id'   => 'image_caption',
                            'type' => 'text',
                        ),
                        array(
                            'name' => 'Embedir un enlace',
                            'desc' => 'Ingrese una URL de youtube, twitter, o instagram. Soporta los servicios enlistados en <a href="http://codex.wordpress.org/Embeds">http://codex.wordpress.org/Embeds</a>.',
                            'id' => 'embed',
                            'type' => 'oembed',
                        ),
                        array(
                            'name' => 'Añadir un Subnodo',
                            'desc' => 'Añade un subnodo con información "envuelta"',
                            'id' => 'subnodo',
                            'type' => 'textarea_small',
                            'repeatable' => true,
                        ),
                    ),
                ),
            ),

    ^that’s the code that’s on the functions.php… and the the last array is the code for the repeatable field

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Could you provide the action hook and callback function as well, instead of just the one field_group? It’ll help me recreate what you have going on more exactly.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Did you ever get this one figured out wlaedimir ?

    Thread Starter wlaedimir

    (@wlaedimir)

    No, I didn’t, in fact, my boss said that it was better to let it aside, so I started to work on other things. So, I still can check this to see if we can get a solution for the other users right?

    Which is the action hook? and the callback? I mean, where can I find them, in the pages where the outputs for this function must be shown?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    you would have some sort of function declaration and a line similar to the following, though the function names won’t match:

    add_filter( 'cmb2_meta_boxes', 'cmb2_event_metaboxes' );
    function cmb2_event_metaboxes() {
        # Code above would be here.
    }

    I was hoping to get all those parts.

    Thread Starter wlaedimir

    (@wlaedimir)

    This is what I found

    // Metaboxes para el resto del tema
    
    function gobcl_metaboxes( $meta_boxes ) {
        $prefix = '_gobcl_'; // Prefix for all fields
        $meta_boxes['field_group'] = array(
            'id'         => 'nodos_automaticos',
            'title'      => __( 'Nodos', 'gobcl' ),
            'pages'      => array( 'page', ),
            'cmb_styles' => true,
            'fields'     => array(
                array(
                    'id'          => $prefix . 'nodos_auto',
                    'type'        => 'group',
                    'description' => __( 'Creación simple de nodos de contenido', 'gobcl' ),
                    'options'     => array(
                        'group_title'   => __( 'Nodo N°{#}', 'gobcl' ), // {#} gets replaced by row number
                        'add_button'    => __( 'Añadir otro nodo', 'gobcl' ),
                        'remove_button' => __( 'Quitar nodo', 'gobcl' ),
                        'sortable'      => true, // beta
                    ),
                    // Fields array works the same, except id's only need to be unique for this group. Prefix is not needed.
                    'fields'      => array(
                        array(
                            'name' => 'Titulo de Nodo',
                            'id'   => 'title',
                            'type' => 'text',
                            // 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types)
                        ),
                        array(
                            'name' => 'Enlace a Página',
                            'id'   => 'link',
                            'type' => 'text',
                        ),
                        array(
                            'name' => 'Descripción o Párrafo para nodo',
                            'description' => 'Escriba una descripción para el contenido de este nodo',
                            'id'   => 'description',
                            'type' => 'wysiwyg',
                            'options' => array(
                                'media_buttons' => false,
                                'textarea_rows' => get_option('default_post_edit_rows', 3)
                            ),
                        ),
                        array(
                            'name' => 'Imagen de cabecera de nodo',
                            'description' => 'Añada una imagen para la cabecera del nodo',
                            'id'   => 'image',
                            'type' => 'file',
                        ),
                        array(
                            'name' => 'Embedir un enlace',
                            'desc' => 'Ingrese una URL de youtube, twitter, o instagram. Soporta los servicios enlistados en <a href="http://codex.wordpress.org/Embeds">http://codex.wordpress.org/Embeds</a>.',
                            'id' => 'embed',
                            'type' => 'oembed',
                        ),
                        array(
                            'name' => 'Subnodo N°1',
                            'desc' => 'Nodos especiales para contenidos envueltos',
                            'id' => 'subnodo1',
                            'type' => 'wysiwyg',
                            'options' => array(
                                'media_buttons' => false,
                                'textarea_rows' => get_option('default_post_edit_rows', 3),
                                'teeny' => true
                            ),
                        ),
                        array(
                            'name' => 'Subnodo N°2',
                            'desc' => 'Nodos especiales para contenidos envueltos',
                            'id' => 'subnodo2',
                            'type' => 'wysiwyg',
                            'options' => array(
                                'media_buttons' => false,
                                'textarea_rows' => get_option('default_post_edit_rows', 3),
                                'teeny' => true
                            ),
                        ),
                        array(
                            'name' => 'Subnodo N°3',
                            'desc' => 'Nodos especiales para contenidos envueltos',
                            'id' => 'subnodo3',
                            'type' => 'wysiwyg',
                            'options' => array(
                                'media_buttons' => false,
                                'textarea_rows' => get_option('default_post_edit_rows', 3),
                                'teeny' => true
                            ),
                        ),
                        array(
                            'name' => 'Subnodo N°4',
                            'desc' => 'Nodos especiales para contenidos envueltos',
                            'id' => 'subnodo4',
                            'type' => 'wysiwyg',
                            'options' => array(
                                'media_buttons' => false,
                                'textarea_rows' => get_option('default_post_edit_rows', 3),
                                'teeny' => true
                            ),
                        ),
                    ),
                ),
            ),
        );
    
        return $meta_boxes;
    }
    
    add_filter( 'cmb_meta_boxes', 'gobcl_metaboxes' );
    
    add_action( 'init', 'cmb_initialize_cmb_meta_boxes', 9999 );
    /**
     * Initialize the metabox class.
     */
    function cmb_initialize_cmb_meta_boxes() {
    
        if ( ! class_exists( 'cmb_Meta_Box' ) )
            require_once 'lib/metabox/init.php';
    }

    If this isn’t enough I can send you the file. In the fields, I replaced the grpup field array that wasn’t working. It was supposed to build this “Subnodo” elements.

    Plugin Author Justin Sternberg

    (@jtsternberg)

    The 'cmb2_meta_boxes' filter is no longer the recommended method for adding fields/metaboxes. Please use the new field/metabox API demonstrated in the included example-functions.php.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    wlaedimir, I’d go with what Justin said, which was my mistake for recommending that specific filter. Regarding the bit above in your last post, that snippet appears to be for the old CMB1 library, which is not the same as what is in CMB2 these days. I’d recommend reviewing the example functions file Justin pointed to and see about getting things updated to better match.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Repeatable Text field on Group-Field doesn't add a new row’ is closed to new replies.