Skip to content

Latest commit

 

History

History
184 lines (169 loc) · 4.64 KB

forms_en.md

File metadata and controls

184 lines (169 loc) · 4.64 KB

Forms

New attr boostrap col

Example field form

->add('text', 'text', array(
    'attr' => array(
        'col' => 'col-lg-6 col-md-6 col-sm-6',
    ),
))

If Select2entityType see below how to configure properly.

Attr boostrap row

Example field form

...
use MWSimple\Bundle\AdminCrudBundle\Form\Type\FormrowType;
...
->add('formrow', FormrowType::class, array(
    'mapped' => false
))

New attr boostrap inline

If you need the checkbox or radio are located inline

->add('checkbox', ChoiceType::class, array(
    'label_attr' => array(
        'class' => 'inline',
    ),
))

Form type: mwspeso - Use Type Number add $

Example field form

->add('numero', \MWSimple\Bundle\AdminCrudBundle\Form\Type\PesoType::class)

mws-datetime class for DateTime type

Example field form

->add('dateTime', DateTimeType::class, [
    'date_widget' => 'single_text',
    'time_widget' => 'text',
    'attr' => [
        'class' => 'mws-datetime',
    ],
])

Use Text editor.

Remember to install assets

php bin/console ckeditor:install
php bin/console assets:install

En el archivo app/config/config.yml

fos_ck_editor:
    autoload: false
    async: true

Field CKEditorType::class Documentation. Example

use FOS\CKEditorBundle\Form\Type\CKEditorType;

$builder
    ->add('field', CKEditorType::class, array(
        'config' => array(
            'uiColor' => '#ffffff',
            //...
        ),
    ))
;

Use DualList.

FormType DualListType::class Documentation. Example

use MWSimple\Bundle\AdminCrudBundle\Form\Type\DualListType;

$builder
    ->add('field', DualListType::class, array(
        'class'    => 'AppDemoBundle:Entity',
        'choice_label' => 'name',
        'multiple' => true,
        'required' => false,
        'expanded' => true,
    ))
;

Use Select2. Documentation

Implement a normal select Select2 adding class mws_select2:

    $builder
        ->add('field', null, [
            'attr' => array(
                'class' => "mws_select2 col-lg-12 col-md-12",
                'col'   => "col-lg-8 col-md-8",
            )
        ])
    ;

Use Select2 Entity. Documentation

In the Entities are required to have the method toString() or you can define a method in the controller

public function __toString()
{
    return (string)$this->getId();
}

Optional Customize the method in the controller:

public function getAutocompleteEntity(Request $request)
{
    ...
    $response = parent::getAutocompleteFormsMwsAction($request, $options, null, "getId");
    ...
}
#### Optional Personalize LIKE: start, end, equal, contains:
```php
public function getAutocompleteEntity(Request $request)
{
    ...
    $response = parent::getAutocompleteFormsMwsAction($request, $options, null, null, "equal");
    ...
}

If entity relationship generates select autocomplete. Personalize field

public function getAutocompleteEntity(Request $request)
{
    $options = array(
        ...
        'field' => "id", #change by field id to use for the search
    );
    ...
}

Personalize query join field, the variable $qb rewrites the original

public function getAutocompleteEntity(Request $request)
{
    $options = array(
        'repository' => "AppBundle:Example",
        'field'      => "id",
    );
    //querybuilder $qb
    $em = $this->getDoctrine()->getManager();

    $qb = $em->getRepository($options['repository'])->createQueryBuilder('a');
    $qb
        ->where("a.".$options['field']." LIKE :term")
        ->orderBy("a.".$options['field'], "ASC")
    ;
    //set querybuilder $qb
    $response = parent::getAutocompleteFormsMwsAction($request, $options, $qb);

    return $response;
}

Type Form. Optional configuration from the documentation tetranz/select2entity-bundle:

Type Form. Correct settings for the type Select2 using bootstrap, use 'class' and 'col'.

    $builder
        ->add('field', \Tetranz\Select2EntityBundle\Form\Type\Select2EntityType::class, array(
            //...
            'attr' => array(
                'class' => "col-lg-12 col-md-12",
                'col'   => "col-lg-8 col-md-8",
            )
        )
    ;

GitHub