From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/web/static/src/js/libs/autocomplete.js | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 addons/web/static/src/js/libs/autocomplete.js (limited to 'addons/web/static/src/js/libs/autocomplete.js') diff --git a/addons/web/static/src/js/libs/autocomplete.js b/addons/web/static/src/js/libs/autocomplete.js new file mode 100644 index 00000000..72f3ee89 --- /dev/null +++ b/addons/web/static/src/js/libs/autocomplete.js @@ -0,0 +1,38 @@ +odoo.define('web.autocomplete.extensions', function () { +'use strict'; + +/** + * The jquery autocomplete library extensions and fixes should be done here to + * avoid patching in place. + */ + +// jquery autocomplete tweak to allow html and classnames +var proto = $.ui.autocomplete.prototype; +var initSource = proto._initSource; + +function filter( array, term ) { + var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" ); + return $.grep( array, function (value_) { + return matcher.test( $( "
" ).html( value_.label || value_.value || value_ ).text() ); + }); +} + +$.extend(proto, { + _initSource: function () { + if ( this.options.html && $.isArray(this.options.source) ) { + this.source = function (request, response) { + response( filter( this.options.source, request.term ) ); + }; + } else { + initSource.call( this ); + } + }, + _renderItem: function (ul, item) { + return $( "
  • " ) + .data( "item.autocomplete", item ) + .append( $( "" )[ this.options.html ? "html" : "text" ]( item.label ) ) + .appendTo( ul ) + .addClass(item.classname); + }, +}); +}); -- cgit v1.2.3