jcchavezs / cmb2-conditionals

Plugin to relate fields in a CMB2 metabox
GNU General Public License v2.0
86 stars 61 forks source link

Unable to make it works, help lease #37

Closed fredleput closed 7 years ago

fredleput commented 7 years ago

Hi, i've red all messages on support forum, but i can't make conditional fields work. here's my function.php file :

// metaboxes for actualites
add_action("cmb2_init", `"utl_register_metabox");
function utl_register_metabox() {
    $prefix = "_utl_cmb_";

    // details d'une actualite
    $utl_actualite_details = new_cmb2_box(array(
        "id"            => "metabox_actualite_details",
        "title"         => "Détails de l'actualité",
        "object_types"  => array("post"),
        "show_on"       => array("key" => "cat-slug", "value" =>array("actualites")),
        "context"       => "normal",
        "priority"      => "high",
        "show_names"    => true
    ));

    $utl_actualite_details->add_field(array(
        "name" => "Cette actualité a-t-elle des détails ?",
        "desc" => "Si oui, un bouton \"En savoir plus\" sera affiché",
        "id"   => $prefix."actualite_savplus",
        "type" => "select",
        "default" => "non",
        "options" => array(
            "non" => "Non",
            "oui" => "Oui"
        )
    ));

    $utl_actualite_details->add_field(array(
        "name" => "Texte de détails",
        "desc" => "Le texte de détails de l'actualite",
        "id"   => $prefix."actualite_details",
        "type" => "text",
        "attributes" => array(
            "data-conditional-id"    => $prefix."actualite_savplus",
            "data-conditional-value" => "oui"
        )
    ));
}

according to me, the actualite_details field should appear only if actualite_savplus select field is on 'oui' value, but it doesn't work. i've checked the field actualite_details has data-conditionnal-id and data-conditional-value property (see screenshot). cmb-fields

Thx