jcchavezs / cmb2-conditionals

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

required attribute not working #62

Open jitmaity21 opened 5 years ago

jitmaity21 commented 5 years ago
$cmb->add_field( array(
    'name'    => __( 'Check', 'cmb2' ),
    'id'      => $prefix . 'type',
    'type'    => 'select',
    'options' => array(
        'type1' => __( 'Type 1', 'cmb2' ),
        'type2' => __( 'Type 2', 'cmb2' ),
        'type3' => __( 'Type 3', 'cmb2' ),
    ),
    'attributes' => array(
        'required'            => true
    ),
    'default' => 'type1',
) );

$cmb->add_field( array(
    'name'       => 'Thumbnail',
    'id'         => $prefix . 'thumb',
    'type'    => 'file',
    'options' => array(
        'url' => false,
    ),
    'text'    => array(
        'add_upload_file_text' => 'Add Thumbnail'
    ),
    'query_args' => array(
        'type' => array(
            'image/gif',
            'image/jpeg',
            'image/png',
        ),
    ),
    'preview_size' => 'thumbnail',
    'attributes' => array(
        'required'            => true,
        'data-conditional-id' => $prefix . 'type',
        'data-conditional-value' => wp_json_encode( array( 'type1', 'type2') ),
    ),

) );

$cmb->add_field( array(
    'name'       => 'PDF',
    'id'         => $prefix . 'pdf',
    'type'    => 'file',
    'options' => array(
        'url' => false,
    ),
    'text'    => array(
        'add_upload_file_text' => 'Add PDF'
    ),
    'query_args' => array(
        'type' => 'application/pdf',
    ),
    'attributes' => array(
        'required'            => true,
        'data-conditional-id'    => $prefix . 'type',
        'data-conditional-value' => 'type3',
    ),
) );