Skip to content
Snippets Groups Projects
Commit 76f258ad authored by Ghislain Loas's avatar Ghislain Loas
Browse files

dev #12691

fix multiple search input auto completion
parent 437eefce
Branches
Tags
5 merge requests!258Dev/13872 Orphee Allow Hold Available Items,!215Dev#12992 Custom Fields,!209Hotline#13914 Album Link Config Menu,!190Dev#12691 Autocomplete,!186Dev#12691 Autocomplete
......@@ -10,43 +10,43 @@
*
* AFI-OPAC 2.0 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with AFI-OPAC 2.0; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
(function ( $ ) {
$.fn.search_autocomplete = function (options) {
var node = $(this);
node.autocomplete({
minLength: options.minLength,
html: true,
source: function(query, response) {
(function($) {
$.widget('ui.search_autocomplete', $.ui.autocomplete, {
_create: function() {
this._super();
this.options.html = true;
this.source = function(query, response) {
var datas = {};
datas[options.dataLabel] = node.val();
$.ajax({
url: options.url,
dataType: 'json',
datas[this.options.dataLabel] = query.term;
$.ajax({
url: this.options.url,
dataType: this.options.dataType,
data: datas,
success: function(data) {response(data);}
});
},
focus: function(event, ui) {
return false;
},
select: function(event, ui) {
node.val(ui.item.value);
node.closest('form').submit();
return false;
}
}).data("ui-autocomplete")._renderItem = function(ul, item) {
};
},
select: function(event, ui) {
$(this).val(ui.item.value);
$(this).closest('form').submit();
return false;
},
_renderItem: function(ul, item) {
return $("<li>")
.data("item.autocomplete", item)
.append("<a>" + item.label + "</a>")
.appendTo(ul);
};
};
} (jQuery));
}
})
})(jQuery);
......@@ -30,31 +30,31 @@ QUnit.module('search_autocomplete', {
dataType : 'json',
dataLabel : 'startsWith',
minLength: 3});
fixture.val('topo');
fixture.autocomplete('search');
}
});
test('autocomplete should call ajax with correct url', function() {
fixture.search_autocomplete('search', 'topo');
equal(options.url, 'my_bokeh/recherche/suggestajax');
});
test('autocomplete should call ajax with correct data', function() {
fixture.search_autocomplete('search', 'topo');
equal(options.data.startsWith, 'topo');
});
test('autocomplete should call ajax with correct data type', function() {
fixture.search_autocomplete('search', 'topo');
equal(options.dataType, 'json');
});
test('autocomplete should no call ajax with expected minLength', function() {
options = null;
fixture.val('op');
fixture.autocomplete('search');
fixture.search_autocomplete('search', 'to');
equal(options, null);
});
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment