]> git.0d.be Git - django-panik-combo.git/blobdiff - panikombo/templates/panikombo/select2.html
replace django-select2 dependency by own code
[django-panik-combo.git] / panikombo / templates / panikombo / select2.html
diff --git a/panikombo/templates/panikombo/select2.html b/panikombo/templates/panikombo/select2.html
new file mode 100644 (file)
index 0000000..4137d9a
--- /dev/null
@@ -0,0 +1,24 @@
+<select style="width: 100%" name="{{ widget.name }}" {% include "django/forms/widgets/attrs.html" %}>
+{% if widget.value != None %}<option value="{{ widget.value }}">{{widget.view_value}}</option>{% endif %}
+</select>
+<script>
+$(function() {
+    var options = {
+      placeholder: '',
+      minimumInputLength: 3,
+      ajax: {
+        url: function() {
+          return "{% url view_name %}";
+        },
+        dataType: 'json',
+        data: function(params) {
+          var query = {
+            term: params.term,
+          }
+          return query;
+        },
+      },
+    };
+    $('select[name={{widget.name}}]').select2(options);
+})
+</script>