PrestaShop Developer Conference
PrestaShop Developer Conference
Paris, France - November 6, 2024
Let's talk code, commerce and open source.

Warning: You are browsing the documentation for PrestaShop 1.7, which is outdated.

You might want to read an updated version of this page for the current version, PrestaShop 8. Read the updated version of this page

Learn how to upgrade to the latest version.

SwitchType

The SwitchType displays a switch with Yes/No values.

Type options

Option Type Default Description
choices array Choices with Yes/No values Choices for switch type
disabled bool false Whether Switch should be disabled or not

Required Javascript components

None.

Code example

Add SwitchType to your form.

<?php

use Symfony\Component\Form\AbstractType;
use PrestaShopBundle\Form\Admin\Type\SwitchType;

class SomeType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('switch', SwitchType::class, [
            // Customized choices with ON/OFF instead of Yes/No
            'choices' => [
                'ON' => true,
                'OFF' => false,
            ],
        ]);
    }
}

Preview example

SwitchType rendered in form