ember-widgets
ember-widgets copied to clipboard
search by group
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;
}
});
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.