Django Select Multiple filter.

         ·

Django has a really nice select multiple field, for choosing multiple items at once with a Javascript chooser..

It is really handy to use when there is a large number of items that have to be chosen from in a select. I am using with JQuery.

To do this, grab SelectFilter2.js from the django-admin media folder, or get it from Django’s GitHub repository. Then to initialize it you can put the following into your code:

[cc lang=“Javascript”]

$(document).ready(function() {

$.each($(“select[multiple]“), function () {

// “Locations” can be any label you want

SelectFilter.init(this.id, “Locations”, 0, “/media/”);

});

});

[/cc]

This will use the SelectFilter on all select multiples and give it a label of locations.

For reference the functions are:

[cc lang=“javascript”]

function(field_id, field_name, is_stacked, admin_media_prefix)

[/cc]

So you could use:

[cc lang=“Javascript”]

SelectFilter.init(“#MySelect”, “Test”, 0, “{{ MEDIA_URL}}img/”);

[/cc]

Then all that needs is styling the select multiple.

comments powered by Disqus