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

    (@tw2113)

    The BenchPresser

    I do not believe CMB2 has that level of repeatability available.

    Thread Starter andp

    (@andp)

    Yes i thought so. Another issue with my repeatable fields is that the remove icon (x) and the toggle icon dont work on the front end. om the backend everything is ok

    thank you

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Could you check your browser’s developer console log to see if any javascript errors are appearing when you click the icons?

    Thread Starter andp

    (@andp)

    hello there i cant see any errors

    Thread Starter andp

    (@andp)

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    It looks like nothing at all is being rendered, which is going to be errors/issues before the javascript comes into play.

    Thread Starter andp

    (@andp)

    i think i did something wrong with my files. what i am doing is that i created a custom plugin. this has the following structure.
    myplugin(folder)
    – myplugin.php

    should i copy the entire cmb2 forlder in my mplugin folder and then put

    if ( file_exists( dirname( __FILE__ ) . ‘/cmb2/init.php’ ) ) {
    require_once dirname( __FILE__ ) . ‘/cmb2/init.php’;
    } elseif ( file_exists( dirname( __FILE__ ) . ‘/CMB2/init.php’ ) ) {
    require_once dirname( __FILE__ ) . ‘/CMB2/init.php’;
    }
    in my php file?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    If you are bundling the CMB2 files as a library in the plugin, then yes you’d want to go that route, but you also need to make sure that those require_once and file_exists paths match up with the hierarchy you’re creating. Those may need to be tweaked a little bit. You can also get rid of part of that if check since you’ll know the capitalization of the folder. Just go with whichever one you’re using for the name.

    Thread Starter andp

    (@andp)

    hello again

    i am trying to work with repeating groups on the frontend but can make it.

    i am using your simple examples. first of all i installed cmb2 plugin from wordpress. then i added these lines in my themes functions. The group works fine on the back end. On the frontend everything works ok except the toggle icon. Any suggestions?

    you can have a look here (https://www.sight79.net/demosite/sample-page/)

    /**
    * Get the bootstrap!
    */
    if ( file_exists( __DIR__ . ‘/cmb2/init.php’ ) ) {
    require_once __DIR__ . ‘/cmb2/init.php’;
    } elseif ( file_exists( __DIR__ . ‘/CMB2/init.php’ ) ) {
    require_once __DIR__ . ‘/CMB2/init.php’;
    }

    //CREATE METABOX
    add_action( ‘cmb2_init’, ‘cmb2_sample_metaboxes’ );
    function cmb2_sample_metaboxes() {
    // Start with an underscore to hide fields from custom fields list
    $prefix = ‘_yourprefix_’;
    $cmb_group = new_cmb2_box( array(
    ‘id’ => $prefix . ‘metabox’,
    ‘title’ => __( ‘Repeating Field Group’, ‘cmb2’ ),
    ‘object_types’ => array( ‘page’, ),
    ) );

    // $group_field_id is the field id string, so in this case: $prefix . ‘demo’
    $group_field_id = $cmb_group->add_field( array(
    ‘id’ => $prefix . ‘demo’,
    ‘type’ => ‘group’,
    ‘description’ => __( ‘Generates reusable form entries’, ‘cmb2’ ),
    ‘options’ => array(
    ‘group_title’ => __( ‘Entry {#}’, ‘cmb2’ ), // {#} gets replaced by row number
    ‘add_button’ => __( ‘Add Another Entry’, ‘cmb2’ ),
    ‘remove_button’ => __( ‘Remove Entry’, ‘cmb2’ ),
    ‘sortable’ => true, // beta
    ),
    ) );
    // Regular text field
    $cmb_group->add_group_field( $group_field_id, array(
    ‘name’ => __( ‘Test Text’, ‘cmb2’ ),
    ‘desc’ => __( ‘field description (optional)’, ‘cmb2’ ),
    ‘id’ => $prefix . ‘text’,
    ‘type’ => ‘text’,
    ‘show_on_cb’ => ‘cmb2_hide_if_no_cats’, // function should return a bool value
    // ‘sanitization_cb’ => ‘my_custom_sanitization’, // custom sanitization callback parameter
    // ‘escape_cb’ => ‘my_custom_escaping’, // custom escaping callback parameter
    // ‘on_front’ => false, // Optionally designate a field to wp-admin only
    // ‘repeatable’ => true,
    ) );
    }

    //FRONTEND METABOX
    add_shortcode( ‘cmb-form’, ‘cmb2_do_frontend_form_shortcode’ );
    function cmb2_do_frontend_form_shortcode( $atts = array() ) {
    global $post;
    if ( ! current_user_can( ‘edit_posts’ ) ) {
    return _e( ‘You do not have permissions to edit this post.’, ‘lang_domain’ );
    }
    if ( ! isset( $atts[‘post_id’] ) ) {
    $atts[‘post_id’] = $post->ID;
    }
    if ( empty( $atts[‘id’] ) ) {
    return “Please add a ‘id’ attribute to specify the CMB2 form to display.”;
    }

    $metabox_id = esc_attr( $atts[‘id’] );
    $object_id = absint( $atts[‘post_id’] );
    $form = cmb2_get_metabox_form( $metabox_id, $object_id );
    return $form;
    }

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Are you familiar with your browser developer tools at all? I believe the toggle stuff is javascript based, and if you’re getting js errors when you try to use it, they should appear in the developer tools console.

    Thread Starter andp

    (@andp)

    hello firebug doesnt give me any erros

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Do you have a publicly accessible link to the page hosting the metaboxes in question?

    Thread Starter andp

    (@andp)

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Looks like the CSS for the hiding isn’t matching up what you have on the frontend. Specifically the following:

    #side-sortables .closed .inside,
    .inner-sidebar .closed .inside {
        display:none
    }

    the .closed .inside part is accurate for you, but the front part of those selectors are likely WP admin specific, and not finding anything for the frontend.

    Until we implement a solution for this, you should be able to prefix a css selector yourself with whatever you see fit in your markup. For example

    #_yourprefix_demo_repeat .closed .inside {}

    and it should take care of it for you.

    Thread Starter andp

    (@andp)

    seems ok after changing the css. thank you michael

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Repeatable Groups’ is closed to new replies.