-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Création du widget "AutoCompete" (typeahead.js)
- Loading branch information
Showing
8 changed files
with
259 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
/** | ||
* Widget de formulaire de type autocomplete | ||
* | ||
* @name olix_autocomplete | ||
* @service olix.formsext.type.autocomplete | ||
* | ||
* @param config : liste des options de typeahead | ||
* @param dataset : liste des options de bloodhound | ||
* @link https://github.com/twitter/typeahead.js | ||
* | ||
* @author Olivier <sabinus52@gmail.com> | ||
* | ||
* @package Olix | ||
* @subpackage FormsExtBootstrapBundle | ||
* | ||
*/ | ||
|
||
namespace Olix\FormsExtBootstrapBundle\Form\Type; | ||
|
||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\FormView; | ||
use Symfony\Component\Form\FormInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | ||
use Symfony\Component\OptionsResolver\Options; | ||
|
||
|
||
|
||
class AutoCompleteType extends AbstractType | ||
{ | ||
|
||
/** | ||
* @see \Symfony\Component\Form\AbstractType::buildView() | ||
*/ | ||
public function buildView(FormView $view, FormInterface $form, array $options) | ||
{ | ||
$view->vars['config'] = $options['config']; | ||
$view->vars['dataset'] = $options['dataset']; | ||
} | ||
|
||
|
||
/** | ||
* @see \Symfony\Component\Form\AbstractType::setDefaultOptions() | ||
*/ | ||
public function setDefaultOptions(OptionsResolverInterface $resolver) | ||
{ | ||
$resolver->setDefaults(array( | ||
'config' => array(), | ||
'dataset' => array(), | ||
)); | ||
|
||
// Les options du widget par défaut | ||
$config = array( | ||
'highlight' => true, | ||
'classNames' => array( | ||
'menu' => 'typeahead-menu', | ||
'suggestion' => 'typeahead-suggestion', | ||
), | ||
); | ||
$dataset = array( | ||
|
||
); | ||
|
||
$resolver->setNormalizers(array( | ||
'config' => function (Options $options, $value) use ($config) { | ||
$result = array_merge($config, $value); | ||
return $result; | ||
}, | ||
'dataset' => function (Options $options, $value) use ($dataset) { | ||
$result = array_merge($dataset, $value); | ||
return $result; | ||
}, | ||
)); | ||
} | ||
|
||
|
||
/** | ||
* @see \Symfony\Component\Form\AbstractType::getParent() | ||
*/ | ||
public function getParent() | ||
{ | ||
return 'text'; | ||
} | ||
|
||
|
||
/** | ||
* @see \Symfony\Component\Form\FormTypeInterface::getName() | ||
*/ | ||
public function getName() | ||
{ | ||
return 'olix_autocomplete'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
Composant TypeAhead.js | ||
====================== | ||
|
||
typeahead.js is a fast and fully-featured autocomplete library | ||
|
||
Demo : http://twitter.github.io/typeahead.js/examples/ | ||
|
||
Source : https://github.com/twitter/typeahead.js | ||
|
||
|
||
### Default usage | ||
|
||
Name of type : `olix_autocomplete` | ||
|
||
``` php | ||
// In class form | ||
|
||
public function buildForm(FormBuilder $builder, array $options) | ||
{ | ||
$builder->add('my_autocomplete1', 'olix_autocomplete', array( | ||
'dataset' => array('local' => array('toto', 'titi', 'tutu')) | ||
)); | ||
|
||
// With attributes | ||
$builder->add('my_autocomplete2', 'olix_autocomplete', array( | ||
'config' => array( | ||
'display' => "'nom'", | ||
'limit' => 10, | ||
'minLength' => 2, | ||
), | ||
'dataset' => array( | ||
'remote' => array( | ||
'url' => $this->generateUrl('my_route_xxxxx', array('term' => 'TERM')), | ||
'wildcard' => 'TERM'), | ||
), | ||
), | ||
); | ||
} | ||
``` | ||
|
||
### Options | ||
|
||
#### highlight | ||
**type** : `boolean`, **default** : `true` | ||
|
||
If true, when suggestions are rendered, pattern matches for the current query in text nodes | ||
|
||
#### hint | ||
**type** : `boolean`, **default** : `true` | ||
|
||
If false, the typeahead will not show a hint. | ||
|
||
#### minLength | ||
**type** : `integer`, **default** : `2` | ||
|
||
The minimum character length needed before suggestions start getting rendered | ||
|
||
#### classNames | ||
**type** : `array`, **default** : | ||
|
||
For overriding the default class names used. [See for more details](https://github.com/twitter/typeahead.js/blob/master/doc/jquery_typeahead.md#class-names) | ||
|
||
#### limit | ||
**type** : `integer`, **default** : `8` | ||
|
||
The max number of suggestions to be displayed | ||
|
||
#### display | ||
**type** : `string`, **default** : none | ||
|
||
For a given suggestion, determines the string representation of it | ||
|
||
|
||
### Dataset | ||
|
||
Bloodhound is the typeahead.js suggestion engine | ||
|
||
[See attributes](https://github.com/twitter/typeahead.js/blob/master/doc/bloodhound.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters