From 18c27f836924864ae8757adb2489efeba643edb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Fri, 6 Oct 2017 00:27:34 +0000 Subject: [PATCH] =?UTF-8?q?Ajoute=20des=20suggestions=20quand=20rien=20n'e?= =?UTF-8?q?st=20=C3=A9crit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templatetags/bootstrap_form_typeahead.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/machines/templatetags/bootstrap_form_typeahead.py b/machines/templatetags/bootstrap_form_typeahead.py index 60a75484..de7869d8 100644 --- a/machines/templatetags/bootstrap_form_typeahead.py +++ b/machines/templatetags/bootstrap_form_typeahead.py @@ -142,7 +142,7 @@ def typeahead_choices( f_value ) : '];' def typeahead_engine () : - return 'var choices = new Bloodhound({ ' \ + return 'var engine = new Bloodhound({ ' \ 'datumTokenizer: Bloodhound.tokenizers.obj.whitespace("value"), ' \ 'queryTokenizer: Bloodhound.tokenizers.whitespace, ' \ 'local: choices, ' \ @@ -153,7 +153,7 @@ def typeahead_datasets( f_name ) : return '{ ' \ 'hint: true, ' \ 'highlight: true, ' \ - 'minLength: 1 ' \ + 'minLength: 0 ' \ '}, ' \ '{ ' \ 'templates: { ' \ @@ -161,7 +161,18 @@ def typeahead_datasets( f_name ) : '}, ' \ 'display: "value", ' \ 'name: "'+f_name+'", ' \ - 'source: choices ' \ + 'source: function(q, sync) {' \ + 'if (q === "") {' \ + 'var nb = 10;' \ + 'var first = [] ;' \ + 'for ( var i = 0 ; i < nb ; i++ ) {' \ + 'first.push(choices[i].value);' \ + '}' \ + 'sync(engine.get(first));' \ + '} else {' \ + 'engine.search(q, sync)' \ + '}' \ + '}' \ '}' def typeahead_updater( f_name ):