Extra Symfony Form Input Types
This bundle includes additional Field Types for Symfony Forms. they include: - "input_boxes" form field type. This input is great for account numbers, abns etc where you want 1 input box per number but the transformer returns the value as a string so it is easy to deal with., (*1)
Open a command console, enter your project directory and execute the following command to download the latest version of this bundle: NOTE: This version is not entirely stable yet, (*2)
$ composer require smada/symfony-type-extras-bundle "dev-master"
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation., (*3)
Then, enable the bundle by adding the following line in the app/AppKernel.php
file of your project:, (*4)
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new Smada\SymfonyTypeExtrasBundle\SmadaSymfonyTypeExtrasBundle(), ); // ... } // ... }
Add in the template so the field knows how to be rendered. You can override this with your own rendering template by adding your own class and changing the value of this setting, (*5)
# app/config/config.yml twig: form: resources: - SmadaSymfonyTypeExtrasBundle:Form:fields.html.twig
Add in the css and js as assets in your assetic config., (*6)
# app/config/config.yml assetic: use_controller: false assets: smada_types_css: inputs: - '@SmadaSymfonyTypeExtrasBundle/Resources/public/css/input-boxes.css' smada_types_js: inputs: - '@SmadaSymfonyTypeExtrasBundle/Resources/public/js/input-boxes.js'
{% stylesheets '@smada_types_css' %} <link rel="stylesheet" href="{{ asset_url }}"/> {% endstylesheets %} {% javascripts '@smada_types_js' %} {% endjavascripts %}
$ php app/console assetic:dump
public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('accountNumber', 'input_boxes', ['boxes' => 10]) }