ember-widgets icon indicating copy to clipboard operation
ember-widgets copied to clipboard

search by group

Open phpepe opened this issue 10 years ago • 1 comments

A nice to have feature is to be able to search by group. Currently if you make us of "optionGroupPath", then only the results items are searchable ("optionValuePath") I dont know coffeescript, but I solved that in my project by extending and overriding "matcher method", here is the snippet in pure JS:

App.SelectComponent = Ember.Widgets.SelectComponent.extend({
   matcher: function(searchText, item) {
     if ( this._super(searchText, item) ) {
          return true; 
     }
     var escapedSearchText, label, regex;
     if (this.get('optionGroupPath')) {
         label = Em.get(item, this.get('optionGroupPath'));
         if (label) {
             escapedSearchText = searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
             regex = new RegExp(escapedSearchText, 'i');
             return regex.test(label);
         }
     }
     return false; 
   }
});

phpepe avatar Dec 10 '14 18:12 phpepe

Cool, I like this idea. Would definitely welcome a PR adding it.

Coffeescript vs JavaScript shouldn't really be an issue as they have essentially the same semantics, but we are tossing around the idea of rewriting in JS if you want to hold out for that.

igillis avatar Dec 30 '14 15:12 igillis