Too many dividers after refreshing listview while a filter criteria is present
Use case:
I have an application with facebook integration. I want them to be able to select friends. When they select a friend, I add it to another list and remove it from the source list.
I set up the first list with auto dividers and enabled filtering. When the user chooses a facebook friend, I remove the <li> from the list view and call refresh.
Issue:
- User enters part of the name as a search filter
- User picks a friend
- I remove the LI from the UL (listview)
- I call listview("refresh") on it
- All the dividers appear, not just the ones that match the current search filter
So if they search for "Eric" that only has one user, so the only divider is currently "E". They tap on the Eric user, all the dividers appear when none should.
Versions:
jQuery 1.8.1
jQuery mobile 1.2.0-rc.1
Google Chrome 21.0.1180.89 running on Mac OSX 10.8.2
HTML code:
- <ul data-role="listview" data-inset="true" data-theme="b" data-filter="true"
- id="fb-friends-listview" data-autodividers="true" data-divider-theme="a">
- </ul>
JavaScript:
- $(document)
- .on("click", ".add-fb-friend",
- function (evt)
- {
- evt.preventDefault();
- var $a = $(evt.target);
- var $li = $a.closest("li");
- var $ul = $li.closest("ul");
- $li.remove();
- $ul.listview("refresh");
- });
Users (li elements) added via javascript. Code in the loop:
- var $ul = $("#fb-friends-listview");
- var array = /* data from facebook */;
- $.each(array,
- function (i, item)
- {
- var fbId = item["uid"];
- var $li = $(document.createElement("li"));
- var $a = $(document.createElement("a"));
- $a.attr({ "href": "#", "class": "add-fb-friend" })
- .text(item["name"])
- .appendTo($li)
- .data("fbID", fbId);
- $ul.append($li);
- });
- $ul.listview("refresh");
- $("#fb-user-popup").popup("open", { "positionTo": "window", "history": false });