How do I maintain the on value with a lightswitch-field as a plugin setting? I'm trying to use a lightswitch-field in a plugin-config. But for some reason it won't get saved. The lightswitch-field is always off.

protected function defineSettings()
{
    return array(
        ...
        'mailerShowInfo' =&gt; array(AttributeType::Bool, 'default' =&gt; false),
        ...
    );
}


_settings.html:

{{  forms.lightswitchField({
        label: "Show info in sidebar?"|t,
        id: 'mailerShowInfo',
        name: 'mailerShowInfo',
        value: settings.mailerShowInfo,
        required: true
    })
}}


I tried to use AttributeType::Number instead, and even used settype() in prepSettings() to force a boolean conversion, but still nothing.

Any idea what I'm missing?
I believe you need to set the on value of your lightswitch field.

on: (settings.mailerShowInfo is defined) ? settings.mailerShowInfo : ""


So, the full settings of your twig code would be:

{{  forms.lightswitchField({
        label: "Show info in sidebar?"|t,
        id: 'mailerShowInfo',
        name: 'mailerShowInfo',
        value: settings.mailerShowInfo,
        required: true
        on: (settings.mailerShowInfo is defined) ? settings.mailerShowInfo : ""
    })
}}