Mopa bootstra bundle choice possibilies

Default settings

Multiple

Expanded

Expanded and multiple

Expanded and multiple (inline)

Checkbox widgets can have help block too

Radio by buttons (btn)

Checkboxes by buttons (inline-btn)

Single checkboxe by button (btn)

Choice form widgets

Here we try to show all possible choice form widgets


And there is a lot to do

FormType Code

// ExampleChoiceFormType.php

<?php
namespace Mopa\Bundle\BootstrapSandboxBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

class ExampleChoiceFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('Choice', 'choice', array(
                'label'        => 'Select list',
                'help_block'  => 'Default settings',
                'choices'      => array('1' => 'one', '2' => 'two'),
            ))
            ->add('Choice_multiple', 'choice', array(
                'label'        => 'Multicon-select',
                'help_block'  => 'Multiple',
                'multiple'     => true,
                'choices'      => array('1' => 'one', '2' => 'two'),
            ))
            ->add('Radio_Buttons', 'choice', array(
                'label'        => 'Radio buttons',
                'help_block'  => 'Expanded',
                'expanded'     => true,
                'choices'      => array('1' => 'one', '2' => 'two'),
            ))
            ->add('Checkboxes', 'choice', array(
                'label'        => 'Checkboxes',
                'help_block'  => 'Expanded and multiple',
                'multiple'     => true,
                'expanded'     => true,
                'choices'      => array('1' => 'one', '2' => 'two'),
            ))
            ->add('Checkboxes_Inline', 'choice', array(
                'label'        => 'Inline checkboxes',
                'help_block'  => 'Expanded and multiple (inline)',
                'multiple'     => true,
                'expanded'     => true,
                'choices'      => array('1' => 'one', '2' => 'two'),
                'widget_type'  => "inline"
            ))
            ->add('Simple_Checkboxes', 'checkbox', array(
                'label'        => 'Simple checkbox',
                'help_block'  => 'Checkbox widgets can have help block too'
            ))
            ->add('Radio_By_Buttons', 'choice', array(
                'widget_type' => 'inline-btn',
                'expanded'    => true,
                'choices'      => array('1' => 'one', '2' => 'two'),
                'label_attr'  => array(
                    'class' => 'btn-default',
                ),
                'help_block'  => 'Radio by buttons (btn)',
            ))
            ->add('Checkboxes_By_Buttons', 'choice', array(
                'widget_type' => 'inline-btn',
                'expanded'    => true,
                'multiple'    => true,
                'choices'      => array('1' => 'one', '2' => 'two'),
                'label_attr'  => array(
                    'class' => 'btn-default',
                ),
                'help_block'  => 'Checkboxes by buttons (inline-btn)',
            ))
            ->add('Button_checkbox', 'checkbox', array(
                'widget_type' => 'inline-btn',
                'attr'  => array(
                    'class' => 'btn btn-danger',
                ),
                'help_block'  => 'Single checkboxe by button (btn)',
            ))
        ;
    }
    public function getName()
    {
        return "MopaBootstraBundle_Choice_Possibilies";
    }
}

Template Code

{# MopaBootstrapSandboxBundle:Examples:choices.html.twig #}

{% extends "MopaBootstrapSandboxBundle::layout.html.twig" %}
{% from 'MopaBootstrapBundle::flash.html.twig' import session_flash %}

{% block headline %}Choice Widgets{% endblock headline %}

{% block content %}
<div class="col-lg-6">
    <form action="#" class="form-horizontal" method="post" {{ form_enctype(form) }}>
        {{ form_widget(form) }}

        <div class="form-actions">
            <button type="submit" class="btn btn-primary">Save changes</button>
            <button type="reset" class="btn">Cancel</button>
        </div>
    </form>
</div>
<div class="col-lg-6">
    <h3>Choice form widgets</h3>
    <p>Here we try to show all possible choice form widgets</p>
    <hr>
    <p>And there is a lot to do</p>
</div>
{% endblock content %}

{% set showTemplate = _self %}{% set showForm = formType %}
Fork me on GitHub