Commits

Patrick Samson committed faa48d5

Added a template for the autocomplete of multiple recipients in version 1.2.x of django-ajax-selects

Comments (0)

Files changed (5)

 # 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.
 
 .. _`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
 ~~~~~~~~~~~~~
 """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
 

postman/templates/autocomplete_postman_multiple_as1-2.html

+{% 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 %}
     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):
     """