From 7e2cde8f310018b2b152574942593fcb581ca984 Mon Sep 17 00:00:00 2001 From: xoxoxo Date: Fri, 16 Sep 2016 22:34:51 +0200 Subject: [PATCH] rewrite selected and queryFilter fn in ra.filtering-multiselect.js --- .../rails_admin/ra.filtering-multiselect.js | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/rails_admin/ra.filtering-multiselect.js b/app/assets/javascripts/rails_admin/ra.filtering-multiselect.js index 95cabbd7a1..3e41a7b918 100644 --- a/app/assets/javascripts/rails_admin/ra.filtering-multiselect.js +++ b/app/assets/javascripts/rails_admin/ra.filtering-multiselect.js @@ -175,22 +175,25 @@ _queryFilter: function(val) { var widget = this; widget._query(val, function(matches) { - var i; + var filtered = []; - for (i in matches) { - if (matches.hasOwnProperty(i) && !widget.selected(matches[i].id)) { + var i; + + for (i = 0; i < matches.length; i++) { + if (!widget.selected(matches[i].id)) { filtered.push(i); } } if (filtered.length > 0) { - widget.collection.html(''); - for (i in filtered) { - widget.collection.append( - $('').attr('value', matches[filtered[i]].id).attr('title', matches[filtered[i]].label).text(matches[filtered[i]].label) - ); + widget.collection[0].innerHTML = ''; + var filteredContainer = []; + for (i = 0; i < filtered.length; i++) { + var newOptions = ''; + filteredContainer.push(newOptions); } + widget.collection[0].innerHTML = filteredContainer.join(""); } else { - widget.collection.html(widget.noObjectsPlaceholder); + widget.collection[0].innerHTML = widget.noObjectsPlaceholder; } }); }, @@ -314,7 +317,9 @@ }, selected: function(value) { - return this.element.find('option[value="' + value + '"]').attr("selected"); + if (this.selection[0].querySelectorAll('option[value="' + value + '"]')[0]) { + return true; + } }, destroy: function() {