Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

If the user has defined its own filtering method always filter the fu…

…ll list of items.

Fixes #4133
Largely inspired by #4135
  • Loading branch information...
commit 35775c563a3882a33f8c4e23e25f531b13fd923f 1 parent e4b0aca
@gseguin gseguin authored
Showing with 10 additions and 6 deletions.
  1. +10 −6 js/widgets/listview.filter.js
View
16 js/widgets/listview.filter.js
@@ -12,9 +12,11 @@ $.mobile.listview.prototype.options.filter = false;
$.mobile.listview.prototype.options.filterPlaceholder = "Filter items...";
$.mobile.listview.prototype.options.filterTheme = "c";
// TODO rename callback/deprecate and default to the item itself as the first argument
-$.mobile.listview.prototype.options.filterCallback = function( text, searchValue, item ) {
- return text.toString().toLowerCase().indexOf( searchValue ) === -1;
-};
+var defaultFilterCallback = function( text, searchValue, item ) {
+ return text.toString().toLowerCase().indexOf( searchValue ) === -1;
+ };
+
+$.mobile.listview.prototype.options.filterCallback = defaultFilterCallback;
$( document ).delegate( ":jqmData(role='listview')", "listviewcreate", function() {
@@ -42,15 +44,17 @@ $( document ).delegate( ":jqmData(role='listview')", "listviewcreate", function(
lastval = $this.jqmData( "lastval" ) + "",
childItems = false,
itemtext = "",
- item;
+ item,
+ // Check if a custom filter callback applies
+ isCustomFilterCallback = listview.options.filterCallback !== defaultFilterCallback;
listview._trigger( "beforefilter", "beforefilter", { input: this } );
// Change val as lastval for next execution
$this.jqmData( "lastval" , val );
- if ( val.length < lastval.length || val.indexOf( lastval ) !== 0 ) {
+ if ( isCustomFilterCallback || val.length < lastval.length || val.indexOf( lastval ) !== 0 ) {
- // Removed chars or pasted something totally different, check all items
+ // Custom filter callback applies or removed chars or pasted something totally different, check all items
listItems = list.children();
} else {
Please sign in to comment.
Something went wrong with that request. Please try again.