Skip to content
This repository
Browse code

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
Ghislain Seguin authored August 02, 2012

Showing 1 changed file with 10 additions and 6 deletions. Show diff stats Hide diff stats

  1. 16  js/widgets/listview.filter.js
16  js/widgets/listview.filter.js
@@ -12,9 +12,11 @@ $.mobile.listview.prototype.options.filter = false;
12 12
 $.mobile.listview.prototype.options.filterPlaceholder = "Filter items...";
13 13
 $.mobile.listview.prototype.options.filterTheme = "c";
14 14
 // TODO rename callback/deprecate and default to the item itself as the first argument
15  
-$.mobile.listview.prototype.options.filterCallback = function( text, searchValue, item ) {
16  
-	return text.toString().toLowerCase().indexOf( searchValue ) === -1;
17  
-};
  15
+var defaultFilterCallback = function( text, searchValue, item ) {
  16
+		return text.toString().toLowerCase().indexOf( searchValue ) === -1;
  17
+	};
  18
+
  19
+$.mobile.listview.prototype.options.filterCallback = defaultFilterCallback;
18 20
 
19 21
 $( document ).delegate( ":jqmData(role='listview')", "listviewcreate", function() {
20 22
 
@@ -42,15 +44,17 @@ $( document ).delegate( ":jqmData(role='listview')", "listviewcreate", function(
42 44
 				lastval = $this.jqmData( "lastval" ) + "",
43 45
 				childItems = false,
44 46
 				itemtext = "",
45  
-				item;
  47
+				item,
  48
+				// Check if a custom filter callback applies
  49
+				isCustomFilterCallback = listview.options.filterCallback !== defaultFilterCallback;
46 50
 
47 51
 			listview._trigger( "beforefilter", "beforefilter", { input: this } );
48 52
 
49 53
 			// Change val as lastval for next execution
50 54
 			$this.jqmData( "lastval" , val );
51  
-			if ( val.length < lastval.length || val.indexOf( lastval ) !== 0 ) {
  55
+			if ( isCustomFilterCallback || val.length < lastval.length || val.indexOf( lastval ) !== 0 ) {
52 56
 
53  
-				// Removed chars or pasted something totally different, check all items
  57
+				// Custom filter callback applies or removed chars or pasted something totally different, check all items
54 58
 				listItems = list.children();
55 59
 			} else {
56 60
 

0 notes on commit 35775c5

Please sign in to comment.
Something went wrong with that request. Please try again.