jcchavezs / cmb2-conditionals

Plugin to relate fields in a CMB2 metabox

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Show / hide entire group of fields

K15Lmk98 opened this issue · comments

This is an automatic translation

Hello,

maybe I did not understand the examples, but I can not condition (show / hide) an entire group of fields, directly from the creation from the main field of the group.

Instead it works if I apply the code to every single field in the group.

The conditional field is outside the group.

Code:

DOES NOT WORK
$cmb_cr_frontpage_image_id = $cmb_cr_frontpage_image->add_field( array( 'id' => PREFIXCMB2 . 'frontpage_image_group', 'type' => 'group', 'name' => __( 'Elenco immagini', 'genesis-theme-cr' ), 'description' => __( 'Di seguito puoi inserire e ordinare le immagini. <strong>DIMENSIONE CONSIGLIATA: 1000x668px.</strong><br /><br />Nota: - È il contenuto testuale sopra all\'immagine che determina l\'altezza dell\'immagine. <br />Non deve essere corto per permettere la corretta sovrapposizione del colore. <br />Mantenere la lunghezza del contenuto e delle immagini più uniformi possibili, <strong>MEGLIO SE UGUALI</strong>.', 'genesis-theme-cr' ), 'options' => array( 'group_title' => __( 'Immagine {#}', 'genesis-theme-cr' ), 'add_button' => __( 'Aggiungi immagine', 'genesis-theme-cr' ), 'remove_button' => __( 'Rimuovi immagine', 'genesis-theme-cr' ), 'sortable' => true, // beta 'closed' => true, // true to have the groups closed by default ), 'data-conditional-id' => PREFIXCMB2 . 'frontpage_image_fonte', 'data-conditional-value' => 'libere', ), ) );

IT WORKS
$cmb_cr_frontpage_image->add_group_field( $cmb_cr_frontpage_image_id, array( 'name' => __( 'Immagine', 'genesis-theme-cr' ), 'desc' => __( '', 'genesis-theme-cr' ), 'id' => PREFIXCMB2 . 'frontpage_image_group_image', 'type' => 'file', 'attributes' => array( 'data-conditional-id' => PREFIXCMB2 . 'frontpage_image_fonte', 'data-conditional-value' => 'libere', ), ) );

I apologize if I have not explained well.
Thanks, Claudio

Hello,
I do not know if it's the correct way, but I've solved it with a little bit of personal javascript.

if ( selectedValue == "posts" ) { frontpage_image_group . hide(); } else if (selectedValue == "libere") { frontpage_image_group . show(); } else { // }

Claudio_