Skip to content

Instantly share code, notes, and snippets.

@superlou
Created August 24, 2014 01:20
Show Gist options
  • Save superlou/43d059731d9b897e55e8 to your computer and use it in GitHub Desktop.
Save superlou/43d059731d9b897e55e8 to your computer and use it in GitHub Desktop.
Uncooperative {{#if}}
<div class='service-selector'>
{{input value=service focus-out="lostFocus"}}
{{#if showMatches}}
<ul class='matches'>
{{#each matchedServices}}
<li>{{name}}</li>
{{/each}}
</ul>
{{/if}}
</div>
export default Ember.Component.extend({
showMatches: false,
inputMatches: function(input, checked) {
input = input.toLowerCase();
checked = checked.toLowerCase();
if (checked.indexOf(input) != -1) {
return true;
} else {
return false;
}
},
matchedServices: function() {
var input = this.get('service')
if (input) {
var _this = this;
return this.get('services').filter(function(item, index, enumerable) {
var isMatch = _this.inputMatches(input, item.get('name'));
if (isMatch) {
_this.set('showMatches', true);
console.log('here');
}
return isMatch;
});
} else {
return Ember.makeArray();
}
}.property('service'),
actions: {
lostFocus: function(event) {
this.set('showMatches', false);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment