Home>Support>State emitter for checkbox

State emitter for checkbox

Notice: This thread is over two years old; the information may be outdated. Please consider creating a new thread if you require free support. If you have an active SiteOrigin Premium license, you can email our premium support desk at [email protected].

Hi,

How can I add a state emitter for checkbox field? E.g. show/hide another field when a single checkbox is checked!

Thank you for this amazing plugin and your support!

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, 6 months ago Greg Priday
    Hi, I Work Here

    Hi Filipe

    Sorry for the late reply. I’m just coming off a little bit of a holiday :)

    I haven’t actually tested state emitters with a checkbox, but I imagine you could do this with a simple conditional state emitter. Something along the lines of

    'state_emitter' => array(
        'callback' => 'conditional',
        'args' => array(
            'group[active]: val',
            'group[inactive]: !val',
        )
    ),
    

    And then you’ll just need to handle that with a state handler – https://siteorigin.com/docs/widgets-bundle/form-building/state-emitters/#heading-state-handlers

    If the standard conditional state emitter doesn’t work for a checkbox, then you could also try a custom state emitter. This would give you fairly fine grained control over the state that’s emitted from the checkbox.

    https://siteorigin.com/docs/widgets-bundle/form-building/state-emitters/#heading-custom-callbacks

    As soon as I get a chance I’ll take a proper look at checkboxes and state emitters. So far, in our own widgets, we’ve only ever needed them for select fields.

  2. 9 years, 3 months ago Filipe

    Hi Greg, thank you for the answer.

    Unfortunately, it doesn’t work with the standard conditional state emitter, at least on my try!

    I want to create a simple switcher, and use the conditional state emitter to show/hide when button is on/off.. :(

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