Skip to content

Commit

Permalink
Merge pull request #287 from WedgeSama/master
Browse files Browse the repository at this point in the history
Select2 default configuration
  • Loading branch information
bamarni committed Aug 7, 2013
2 parents 3c92eaf + 5cffe76 commit b97b827
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
4 changes: 4 additions & 0 deletions DependencyInjection/Configuration.php
Expand Up @@ -359,6 +359,10 @@ private function addSelect2(ArrayNodeDefinition $rootNode)
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')->defaultFalse()->end()
->arrayNode('configs')
->prototype('variable')
->end()
->end()
->end()
->end()
->end()
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/GenemuFormExtension.php
Expand Up @@ -257,6 +257,7 @@ private function registerSelect2Configuration(array $configs, ContainerBuilder $
$typeDef = new DefinitionDecorator($serviceId);
$typeDef
->addArgument($type)
->addArgument($configs['configs'])
->addTag('form.type', array('alias' => 'genemu_jqueryselect2_'.$type))
;

Expand Down
12 changes: 5 additions & 7 deletions Form/JQuery/Type/Select2Type.php
Expand Up @@ -28,10 +28,13 @@
class Select2Type extends AbstractType
{
private $widget;

private $configs;

public function __construct($widget)
public function __construct($widget, array $configs = array())
{
$this->widget = $widget;
$this->configs = $configs;
}

/**
Expand Down Expand Up @@ -67,12 +70,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$defaults = array(
'placeholder' => 'Select a value',
'allowClear' => false,
'minimumInputLength' => 0,
'width' => 'off',
);
$defaults = $this->configs;
$resolver
->setDefaults(array(
'configs' => $defaults,
Expand Down
19 changes: 19 additions & 0 deletions Resources/doc/jquery/select2/config.md
@@ -0,0 +1,19 @@
# jQuery Select2 configuration

By default, just use the default configuration of select2.

### Configuration example:
``` yml
# app/config/config.yml
genemu_form:
select2:
enabled: true
configs:
placeholder: Select a value
width: off
allowClear: false
minimumInputLength: 0
```

see officiel select2's documentation for more information:
http://ivaynberg.github.io/select2/#documentation
3 changes: 2 additions & 1 deletion Resources/doc/jquery/select2/index.md
Expand Up @@ -42,4 +42,5 @@ documentation.

## Extra

1. [Ajax](https://github.com/genemu/GenemuFormBundle/blob/master/Resources/doc/jquery/select2/ajax.md)
1. [Ajax](https://github.com/genemu/GenemuFormBundle/blob/master/Resources/doc/jquery/select2/ajax.md)
2. [Configuration example](https://github.com/genemu/GenemuFormBundle/blob/master/Resources/doc/jquery/select2/config.md)

0 comments on commit b97b827

Please sign in to comment.