Viewing 4 replies - 1 through 4 (of 4 total)
  • Hey there,

    you can use a ‘required’ argument in select control as follows

    $controls[] = array(
    		'type'        => 'select',
    		'setting'     => 'select_demo_2',
    		'label'       => __( 'This is the label', 'kirki' ),
    		'description' => __( 'This is the control description', 'kirki' ),
    		'help'        => __( 'This is some extra help. You can use this to add some additional instructions for users. The main description should go in the "description" of the field, this is only to be used for help tips.', 'kirki' ),
    		'section'     => 'select_section',
    		'default'     => 'option-1',
    		'priority'    => 10,
    		'choices'     => array(
    			'option-1' => __( 'Option 1', 'kirki' ),
    			'option-2' => __( 'Option 2', 'kirki' ),
    			'option-3' => __( 'Option 3', 'kirki' ),
    			'option-4' => __( 'Option 4', 'kirki' ),
    		),
    		'required' => array(
    			array(
    				'setting' => 'checkbox_demo',
    				'operator' => '==',
    				'value' => 1
    			)
    		)
    	);

    Hope that helps,
    Dimitris

    Thread Starter Daniel

    (@puntofape)

    Thanks! works like a charm 🙂

    Show/hide conditions work!

    Now, how to make so that default value (#000) is applied only if checkbox has been ticked?

    $fields[] = array(
            'type'        => 'checkbox',
            'setting'     => 'cta_border_color_on',
            'label'       => __( 'Include Border', 'tourtiger' ),
            'section'     => 'hero_area_cta',
            'default'     => 0,
            'priority'    => 29,
        );
    
        $fields[] = array(
            'type'        => 'color',
            'setting'     => 'cta_border_color',
            'label'       => __( 'Border Color', 'tourtiger' ),
            'section'     => 'hero_area_cta',
            'default'     => '#000',
            'priority'    => 29,
            'required'  =>  array(
                array(
                    'setting'   =>  'cta_border_color_on',
                    'operator'  =>  '==',
                    'value' =>  1
                )
            ),
            'output' => array(
                array(
                'element'  => '.btn',
                'property' => 'border-color',
                ),
            )
        );

    The ‘required’ argument just hides the control until the dependencies are being met.
    In order to do so, you should remove the ‘output’ argument and use that logic and CSS in a custom function.

    Of course, this can be a matter of debate, as a feature request. You can always use github’s issue tracker for proposals. 🙂

    Cheers,
    Dimitris

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Conditional controls’ is closed to new replies.