Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix for issue #4133 - check all items on each change when custom filter callback applies #4135

Closed
wants to merge 1 commit into from

2 participants

@cjindustries

Fix for issue #4133 - check all items on each change when custom filter callback applies. This allows custom filters to truly add their own interpretation of the input filter value.

@cjindustries

Also permits forced re-filtering of the lists with $("#myList input.ui-input-text").trigger('change') after a listview refresh.

@johnbender johnbender commented on the diff
js/jquery.mobile.listview.filter.js
@@ -43,11 +43,16 @@ $( document ).delegate( ":jqmData(role='listview')", "listviewcreate", function(
itemtext = "",
item;
+ // Check if a custom filter callback applies
+ var isCustomFilterCallback = listview.options.filterCallback !=
+ $.mobile.listview.prototype.options.filterCallback;

I think check only works when the callback is defined using the widget factory method

$( "#mylist" ).listview( 'option', 'filterCallback', yourFilterFunction );

If the user sets the value via the prototype options value eg,

$( document ).bind( "mobileinit", function(){
  $.mobile.listview.prototype.options.filterCallback = function(){
    console.log( "foo" );
  }
});

This check will always return true though it's clearly a custom callback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@johnbender

Other than the inline comment I agree with the suggested behavior. This will probably have to wait until 1.2 though.

@johnbender

I'm going to close this one because we haven't seen a response on the filter comparison.

@johnbender johnbender closed this
@npmcomponent npmcomponent referenced this pull request from a commit in npmcomponent/cbou-jquery-mobile
@gseguin gseguin If the user has defined its own filtering method always filter the fu…
…ll list of items.

Fixes #4133
Largely inspired by jquery/jquery-mobile#4135
35775c5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 20, 2012
  1. @cjindustries
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 2 deletions.
  1. +7 −2 js/jquery.mobile.listview.filter.js
View
9 js/jquery.mobile.listview.filter.js
@@ -43,11 +43,16 @@ $( document ).delegate( ":jqmData(role='listview')", "listviewcreate", function(
itemtext = "",
item;
+ // Check if a custom filter callback applies
+ var isCustomFilterCallback = listview.options.filterCallback !=
+ $.mobile.listview.prototype.options.filterCallback;

I think check only works when the callback is defined using the widget factory method

$( "#mylist" ).listview( 'option', 'filterCallback', yourFilterFunction );

If the user sets the value via the prototype options value eg,

$( document ).bind( "mobileinit", function(){
  $.mobile.listview.prototype.options.filterCallback = function(){
    console.log( "foo" );
  }
});

This check will always return true though it's clearly a custom callback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
// 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, removed chars or pasted something totally different; check all items
listItems = list.children();
} else {
Something went wrong with that request. Please try again.