Home>Support>Emitting a State to Hide/Show Widget Option in another Widget Class

Emitting a State to Hide/Show Widget Option in another Widget Class

I realize this title may be confusing – but let me explain.

I have a custom widget named “Card” that has a plethora of settings for icons, headings, background images etc… I also have a card group widget which has some specific settings for the group as a whole (such as different templates).

There is a template that should force the use of a background image for all cards in that group if the template select field is set to a particular value.

In my Card Group widget I have something like this (some options removed for brevity):

'tpl' => [
    'type' => 'select',
    'default' => 'default',
    'options' => [
        'default' => 'Default (Icons)',
        'bg-img-with-hover' => 'Background Image w/ Hover',
    ],
    'state_emitter' => [
        'callback' => 'select',
        'args' => ['tpl']
    ],
],

and in my Card widget I have a handler configured on a field to be conditionally shown/hidden on the emitted state from the field referenced above (some options removed for brevity):

‘icon’ => [
‘state_handler’ => [
‘tpl[default]’ => [‘show’],
‘tpl[bg-img-with-hover]’ => [‘hide’],
],
]

This doesn’t seem to work – and I am unsure if it can work the way I would like it to.

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

  1. 7 months, 19 days ago Alex S Hi, I Work Here

    Hi Derek,

    Unfortunately, state emitters are widget specific so this isn’t directly possible. This is due to widget data being retrieved from the server upon opening the widget so it’s not accessible to Page Builder prior to that point.

    You could allow for what you’re after by setting up the Card Group widget to add the Card widget directly. This will allow for the state emitters to work as expected and allow for all of the cards to be directly grouped. This can be done using the widget form field and a repeater form field.

    Kind regards,
    Alex

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