From 2894609500e1b978fd41ed7e1663c5329c3fda65 Mon Sep 17 00:00:00 2001 From: Patrick Samson Date: Mon, 3 Sep 2012 22:26:28 +0200 Subject: [PATCH] Added a template for the autocomplete of multiple recipients in version 1.2.x of django-ajax-selects --- docs/conf.py | 4 +- docs/features.rst | 4 +- postman/__init__.py | 4 +- .../autocomplete_postman_multiple_as1-2.html | 59 +++++++++++++++++++ postman/tests.py | 2 +- 5 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 postman/templates/autocomplete_postman_multiple_as1-2.html diff --git a/docs/conf.py b/docs/conf.py index 49b1578..4cc6def 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -45,9 +45,9 @@ copyright = u'2010, Patrick Samson' # built documents. # # The short X.Y version. -version = '2.0' +version = '2.1' # The full version, including alpha/beta/rc tags. -release = '2.0.0' +release = '2.1.0a1' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/features.rst b/docs/features.rst index 59904c1..4b44527 100644 --- a/docs/features.rst +++ b/docs/features.rst @@ -233,7 +233,9 @@ In case of version 1.2.x of django-ajax-selects: .. _`jQuery UI demos`: http://jqueryui.com/demos/autocomplete/multiple-remote.html - The directory `postman/templates/` doesn't currently provide any examples for this version. + You can use the following working implementation example: + + * :file:`postman/templates/autocomplete_postman_multiple_as1-2.html` Customization ~~~~~~~~~~~~~ diff --git a/postman/__init__.py b/postman/__init__.py index 13e72d9..5f4cc3b 100644 --- a/postman/__init__.py +++ b/postman/__init__.py @@ -1,8 +1,8 @@ """A messaging application for Django""" # following PEP 386: N.N[.N]+[{a|b|c|rc}N[.N]+][.postN][.devN] -VERSION = (2, 0, 0) -PREREL = () +VERSION = (2, 1, 0) +PREREL = ('a', 1) POST = 0 DEV = 0 diff --git a/postman/templates/autocomplete_postman_multiple_as1-2.html b/postman/templates/autocomplete_postman_multiple_as1-2.html new file mode 100644 index 0000000..7557acc --- /dev/null +++ b/postman/templates/autocomplete_postman_multiple_as1-2.html @@ -0,0 +1,59 @@ +{% extends "autocomplete.html" %}{% comment %} +This is a custom template for django-ajax-selects version 1.2+ (not for 1.1.4/5). +Channel: postman_multiple_as1-2 +Form Field: AutoCompleteField +Usage: Entering of multiple values. + +There is no such template provided in the django-ajax-selects application. + +{% endcomment %} +{% block script %} + addAutoComplete("{{html_id}}", function(html_id) { + function split(val) { + return val.split(/,\s*/); + } + function extractLast(term) { + return split(term).pop(); + } + + $("#"+html_id) + // don't navigate away from the field on tab when selecting an item + .bind("keydown", function(event) { + if (event.keyCode === $.ui.keyCode.TAB && + $(this).data("autocomplete").menu.active) { + event.preventDefault(); + } + }) + .autocomplete({ + source: function(request, response) { + $.getJSON("{{lookup_url}}", { + term: extractLast(request.term) + }, response); + }, + search: function() { + // custom minLength + var term = extractLast(this.value); + if (term.length < {{min_length}}) { + return false; + } + }, + focus: function() { + // prevent value inserted on focus + return false; + }, + select: function(event, ui) { + var terms = split(this.value); + // remove the current input + terms.pop(); + // add the selected item + terms.push(ui.item.value); + // add placeholder to get the comma-and-space at the end + terms.push(""); + this.value = terms.join(", "); + $(this).trigger("added"); + return false; + } + }).autocompletehtml(); + }); +{% block extra_script %}{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/postman/tests.py b/postman/tests.py index 64f4fa3..400da37 100644 --- a/postman/tests.py +++ b/postman/tests.py @@ -76,7 +76,7 @@ class GenericTest(TestCase): Usual generic tests. """ def test_version(self): - self.assertEqual(sys.modules['postman'].__version__, "2.0.0") + self.assertEqual(sys.modules['postman'].__version__, "2.1.0a1") class BaseTest(TestCase): """ -- 2.39.5