summaryrefslogtreecommitdiff
path: root/website/static/admin/js/autocomplete.js
diff options
context:
space:
mode:
authorPrashant S2019-10-03 12:30:03 +0530
committerGitHub2019-10-03 12:30:03 +0530
commit5b1c6a211e89fca4b7caf052befa2e570ecdfc4a (patch)
tree9cba0c741a7cfe3222e2c17401e72b2acc8dedf7 /website/static/admin/js/autocomplete.js
parentbb9ed5af5e0a9737c89f343ea9d65fe77e25da69 (diff)
parentcb37e15ceb336de7ba94d90805ef1531c47d5c96 (diff)
downloadR_on_Cloud_Web_Interface-5b1c6a211e89fca4b7caf052befa2e570ecdfc4a.tar.gz
R_on_Cloud_Web_Interface-5b1c6a211e89fca4b7caf052befa2e570ecdfc4a.tar.bz2
R_on_Cloud_Web_Interface-5b1c6a211e89fca4b7caf052befa2e570ecdfc4a.zip
Merge pull request #4 from prashantsinalkar/master
Updated code for falsk api
Diffstat (limited to 'website/static/admin/js/autocomplete.js')
-rw-r--r--website/static/admin/js/autocomplete.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/website/static/admin/js/autocomplete.js b/website/static/admin/js/autocomplete.js
new file mode 100644
index 0000000..65c0702
--- /dev/null
+++ b/website/static/admin/js/autocomplete.js
@@ -0,0 +1,37 @@
+(function($) {
+ 'use strict';
+ var init = function($element, options) {
+ var settings = $.extend({
+ ajax: {
+ data: function(params) {
+ return {
+ term: params.term,
+ page: params.page
+ };
+ }
+ }
+ }, options);
+ $element.select2(settings);
+ };
+
+ $.fn.djangoAdminSelect2 = function(options) {
+ var settings = $.extend({}, options);
+ $.each(this, function(i, element) {
+ var $element = $(element);
+ init($element, settings);
+ });
+ return this;
+ };
+
+ $(function() {
+ // Initialize all autocomplete widgets except the one in the template
+ // form used when a new formset is added.
+ $('.admin-autocomplete').not('[name*=__prefix__]').djangoAdminSelect2();
+ });
+
+ $(document).on('formset:added', (function() {
+ return function(event, $newFormset) {
+ return $newFormset.find('.admin-autocomplete').djangoAdminSelect2();
+ };
+ })(this));
+}(django.jQuery));