From 3c5d38918b3ddca8361f96e452402e1154fa8876 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 21 Mar 2013 16:51:23 +0100 Subject: [PATCH] [FIX] filter preceded by an invisible filter in the same group On click on a filter in the drawer, FilterGroup would just match the offset of the filter in the group's DOM with an index in the internal #filters array. This worked until invisible fields, and then again only for filters *preceded* by an invisible sibling in the same group: invisible filters are not rendered in the DOM, so the indexes would get out of sync. Fix by using explicit indexes stored in a filter's @data-index and using that to get the filter object/node. An alternative fix (but hackier I think): instead of not rendering invisible filters, render them with display: none. Remains an option in the future if needed... lp bug: https://launchpad.net/bugs/1157125 fixed bzr revid: xmo@openerp.com-20130321155123-211iht7c6zme712e --- addons/web/static/src/js/search.js | 2 +- addons/web/static/src/xml/base.xml | 3 ++- addons/web/static/test/search.js | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js index d7331d2cda8..48a796987c8 100644 --- a/addons/web/static/src/js/search.js +++ b/addons/web/static/src/js/search.js @@ -1136,7 +1136,7 @@ instance.web.search.FilterGroup = instance.web.search.Input.extend(/** @lends in }); }, toggle_filter: function (e) { - this.toggle(this.filters[$(e.target).index()]); + this.toggle(this.filters[Number($(e.target).data('index'))]); }, toggle: function (filter) { this.view.query.toggle(this.make_facet([this.make_value(filter)])); diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 1387da6f5fc..c9adc91a6ad 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -1521,7 +1521,8 @@ diff --git a/addons/web/static/test/search.js b/addons/web/static/test/search.js index ee7a7730ded..6c4b6d61d3c 100644 --- a/addons/web/static/test/search.js +++ b/addons/web/static/test/search.js @@ -1400,6 +1400,26 @@ openerp.testing.section('search.invisible', { return done; }); }); + test('invisible-previous-sibling', {asserts: 3}, function (instance, $fix, mock) { + var view = makeView(instance, mock, {}, [ + '', + '', + '', + '', + '', + ''].join('')); + return view.appendTo($fix) + .done(function () { + // Select filter 3 + $fix.find('.oe_searchview_filters ul li:contains("filter 3")').click(); + equal(view.query.length, 1, "should have selected a filter"); + var facet = view.query.at(0); + strictEqual(facet.values.at(0).get('label'), "filter 3", + "should have correctly labelled the facet"); + deepEqual(view.build_search_data().contexts, [{test: 3}], + "should have built correct context"); + }); + }); // Invisible filter groups should not appear in the drawer // Group invisibility should be inherited by children test('group-invisibility', {asserts: 6}, function (instance, $fix, mock) {