Skip to content

Commit

Permalink
Merge pull request sonata-project#3448 from bgaleotti/autocomplete-co…
Browse files Browse the repository at this point in the history
…nfig

Autocomplete options
  • Loading branch information
pulzarraider committed Dec 4, 2015
2 parents 708a075 + 3b9d011 commit 4728a07
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Form/Type/ModelAutocompleteType.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public function buildView(FormView $view, FormInterface $form, array $options)
$view->vars['req_param_name_search'] = $options['req_param_name_search'];
$view->vars['req_param_name_page_number'] = $options['req_param_name_page_number'];
$view->vars['req_param_name_items_per_page'] = $options['req_param_name_items_per_page'];
$view->vars['quiet_millis'] = $options['quiet_millis'];
$view->vars['cache'] = $options['cache'];

// CSS classes
$view->vars['container_css_class'] = $options['container_css_class'];
Expand Down Expand Up @@ -120,6 +122,8 @@ public function configureOptions(OptionsResolver $resolver)
'placeholder' => '',
'minimum_input_length' => 3, //minimum 3 chars should be typed to load ajax data
'items_per_page' => 10, //number of items per page
'quiet_millis' => 100,
'cache' => false,

'to_string_callback' => null,

Expand Down
6 changes: 6 additions & 0 deletions Resources/doc/reference/form_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,12 @@ minimum_input_length
items_per_page
defaults to 10. Number of items per one ajax request.

quiet_millis
defaults to 100. Number of milliseconds to wait for the user to stop typing before issuing the ajax request.

cache
defaults to false. Set to true, if the requested pages should be cached by the browser.

url
defaults to "". Target external remote URL for ajax requests.
You usually should not need to set this manually.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ file that was distributed with this source code.
ajax: {
url: '{{ url ?: path(route.name, route.parameters|default([]))|e('js') }}',
dataType: 'json',
quietMillis: 100,
quietMillis: {{ quiet_millis }},
cache: {{ cache ? 'true' : 'false' }},
data: function (term, page) { // page is the one-based page number tracked by Select2
{% block sonata_type_model_autocomplete_ajax_request_parameters %}
return {
Expand Down
2 changes: 2 additions & 0 deletions Tests/Form/Type/ModelAutocompleteTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public function testGetDefaultOptions()
$this->assertSame('', $options['placeholder']);
$this->assertSame(3, $options['minimum_input_length']);
$this->assertSame(10, $options['items_per_page']);
$this->assertSame(100, $options['quiet_millis']);
$this->assertSame(false, $options['cache']);
$this->assertSame('', $options['width']);
$this->assertFalse($options['dropdown_auto_width']);

Expand Down

0 comments on commit 4728a07

Please sign in to comment.