添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

I want to style a checkbox as a switch, but I don’t know how to achieve this.

I’m using bootstrap 4.6.2 and TWBS. I thought something like this would do the trick but it doesn’t.

        $this->add([
            'type' => Checkbox::class,
            'name' => 'test',
            'options' => [
                'label' => 'netto/brutto',
                'switch' => true,

What am I missing?

Hey there,

the first question must be: Do you want to rely on an additional dependency like Bootstrap or something else, or do you want to archieve your own solution?

Edit: Okay, it 's early and I 'm not yet done with my first coffee. Haven 't read that you already use Bootstrap and TWBS. So my question is obsolete. Just ignore it. :wink:

If switch true was the only option which could work they would have shared it in the doc. They’ve other options too. I’ve not used it and I don’t only switch option true is needed then why they didn’t show with the option true case? I would say stick with the docs as it or build your own. Also, you’re using BS 4, not 5. Sir 681.

If the markup doesn’t end up looking like <input type="checkbox" switch name="foo">, then the switch attribute is not supported by Laminas form - Open an issue or a PR to add it.

If you don’t see native browser switch styling, then it’s not supported by your browser. From what I know, Safari has native styling but I’m unsure about other browsers.