Home>Support>State Emitters Use ? Some Example ?

State Emitters Use ? Some Example ?

Hi, i love your plugn.
I’d like help to use State Emitters Functions.
If for example i have:

'slider_type' => array(
				'type' => 'radio',
				'label' => __( 'Select type of Slider', 'widget-form-fields-text-domain' ),
				'options' => array(
					'1' => 'Slider 1',
					'2' => 'Slider 2'
				),
				'default' => '1'
			),

And i wanna that selecting option with value = ‘2’ my widget shows:

'slider_2' => array(
				'type' => 'select',
				'label' => __( 'Select  Slider 2', 'widget-form-fields-text-domain' ),
				'options' => $array_slides2
			),

How can i do it ??

Thanks

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 9 years, 5 months ago Greg Priday
    Hi, I Work Here

    Hi Francesco

    Awesome to see you’re developing for the Widgets Bundle! And especially awesome to see you’re using state emitters. It’s a really powerful new feature we added in a recent update.

    So the first step will be to attach a state emitter to your slider_type field. This will emit the state to the rest of the form.

    'slider_type' => array(
    	'type' => 'radio',
    	'label' => __( 'Select type of Slider', 'widget-form-fields-text-domain' ),
    	'options' => array(
    		'1' => 'Slider 1',
    		'2' => 'Slider 2'
    	),
    	'default' => '1',
    	'state_emitter' => array(
    		'callback' => 'select',
    		'args' => array( 'slider_type' )
    	),
    ),
    

    The next step is to add a state handler to your slider_2 field. This will handle the slider_type state by showing the field if this state is set to 1 and showing it if it’s set to 2.

    'slider_2' => array(
    	'type' => 'select',
    	'label' => __( 'Select  Slider 2', 'widget-form-fields-text-domain' ),
    	'options' => $array_slides2,
    	'state_handler' => array(
    		'slider_type[1]' => array('hide'),
    		'slider_type[2]' => array('show'),
    	)
    ),
    

    Hope that points you in the right direction. Here’s a complete guide on using state emitters – https://siteorigin.com/docs/widgets-bundle/form-building/state-emitters/

  2. 9 years, 5 months ago Francesco Prestipino

    Thanks ! It works perfectly !

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More