From 00c3d2ed3cdc7cafa11a02ed5744a8ee00249ebd Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 15 Mar 2016 21:57:43 +0000 Subject: [PATCH] allow to dynamic change autocomplete_params and make minChars a widget attribute --- etemplate/js/et2_widget_taglist.js | 32 ++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/etemplate/js/et2_widget_taglist.js b/etemplate/js/et2_widget_taglist.js index 6c5185eb4d..7428907174 100644 --- a/etemplate/js/et2_widget_taglist.js +++ b/etemplate/js/et2_widget_taglist.js @@ -121,6 +121,12 @@ var et2_taglist = (function(){ "use strict"; return et2_selectbox.extend([et2_IR type: "string", default: null, description: "group results by given JSON attribute" + }, + minChars: { + name: "chars to start query", + type: "integer", + default: 3, + description: "minimum number of characters before expanding the combo" } }, @@ -233,7 +239,8 @@ var et2_taglist = (function(){ "use strict"; return et2_selectbox.extend([et2_IR width: this.options.width, // propagate width highlight: false, // otherwise renderer have to return strings selectFirst: true, - groupBy: this.options.groupBy && typeof this.options.groupBy == 'string' ? this.options.groupBy : null + groupBy: this.options.groupBy && typeof this.options.groupBy == 'string' ? this.options.groupBy : null, + minChars: parseInt(this.options.minChars) ? parseInt(this.options.minChars) : 0 }, this.lib_options); if(this.options.height) { @@ -278,8 +285,10 @@ var et2_taglist = (function(){ "use strict"; return et2_selectbox.extend([et2_IR // Bind keyup so we can start ajax search when we like .on('keyup.start_search', jQuery.proxy(this._keyup, this)) .on('blur', jQuery.proxy(function() { - this.div.removeClass('ui-state-active'); - this.resize(); + if (this.div) { + this.div.removeClass('ui-state-active'); + this.resize(); + } }, this)) // Hide tooltip when you're editing, it can get annoying otherwise .on('focus', function() { @@ -516,6 +525,21 @@ var et2_taglist = (function(){ "use strict"; return et2_selectbox.extend([et2_IR } }, + /** + * Set autocomplete parameters + * + * @param {object} _params + */ + set_autocomplete_params: function(_params) + { + if (this.options.autocomplate_params != _params) + { + this.options.autocomplate_params = _params; + + if (this.taglist) this.taglist.setDataUrlParams(_params); + } + }, + /** * Set the list of suggested options to a static list. * @@ -727,7 +751,7 @@ var et2_taglist = (function(){ "use strict"; return et2_selectbox.extend([et2_IR label: v }; } - else if (this.taglist && + else if (this.taglist && // Check current selection to avoid going back to server (result = $j.grep(this.taglist.getSelection(), function(e) { return e.id == v;