ember-cli-auto-complete
Advanced tools
Comparing version 0.2.1 to 1.0.0-beta.1
@@ -62,9 +62,5 @@ import Ember from "ember"; | ||
self.set("visibility", HIDDEN); | ||
if (!self.get("selectedFromList")) { | ||
var value = this.get("selectedValue"); | ||
var optionsToMatch = this.get("optionsToMatch"); | ||
if (optionsToMatch.indexOf(value) === -1) { | ||
self.set("inputVal", ""); | ||
self.set("selectedValue", ""); | ||
} | ||
if (!self.get("selectedFromList") && !self.hasInputMatchingSuggestion()) { | ||
self.set("inputVal", ""); | ||
self.set("selectedValue", ""); | ||
} | ||
@@ -84,9 +80,5 @@ }; | ||
this.set("visibility", HIDDEN); | ||
} else { | ||
var value = this.get("selectedValue"); | ||
var optionsToMatch = this.get("optionsToMatch"); | ||
if (optionsToMatch.indexOf(value) >= 0) { | ||
this.set("selectedFromList", true); | ||
this.set("visibility", HIDDEN); | ||
} | ||
} else if (this.hasInputMatchingSuggestion()) { | ||
this.set("selectedFromList", true); | ||
this.set("visibility", HIDDEN); | ||
} | ||
@@ -99,2 +91,9 @@ } | ||
onInput: Ember.observer('selectedValue', function() { | ||
var options = this.get("options"); | ||
var input = this.getWithDefault("selectedValue", ""); | ||
this.set("suggestions", this.determineSuggestions(options, input)); | ||
}), | ||
highlight: function (direction) { | ||
@@ -114,2 +113,10 @@ var length = this.get("suggestions").length; | ||
}, | ||
hasInputMatchingSuggestion: function() { | ||
var suggestions = this.get('suggestions'); | ||
var input = this.getWithDefault('selectedValue', '').toLowerCase(); | ||
if (suggestions.length !== 1) { return false; } | ||
return input === suggestions[0].get(this.get('valueProperty')).toLowerCase(); | ||
}, | ||
actions: { | ||
@@ -116,0 +123,0 @@ selectItem: function (item) { |
{ | ||
"name": "ember-cli-auto-complete", | ||
"version": "0.2.1", | ||
"version": "1.0.0-beta.1", | ||
"description": "ember-cli addon that provides type-ahead selection for text inputs", | ||
@@ -5,0 +5,0 @@ "directories": { |
@@ -21,8 +21,7 @@ # ember-cli-auto-complete | ||
First add a custom component that extends AutoComplete. In this component you need to add 2 computed properties and 1 string variable. | ||
First add a custom component that extends AutoComplete. In this component you need to add 1 function and 1 string variable. | ||
``` | ||
1) suggestions: this computed will determine how the list of options is filtered as the user enters text | ||
2) optionsToMatch: this computed will determine if the value entered is valid (when the user omits to click/enter/tab the selection) | ||
3) valueProperty: this string should be the value property for the options passed in (think selectbox value/label) | ||
1) determineSuggestions: this function will determine how the list of options is filtered as the user enters text (it gets passed the available options and the users input) | ||
2) valueProperty: this string should be the value property for the options passed in (think selectbox value/label) | ||
``` | ||
@@ -35,17 +34,9 @@ | ||
valueProperty: "code", | ||
suggestions: function() { | ||
var inputVal = this.get("inputVal") || ""; | ||
return this.get("options").filter(function(item) { | ||
return item.get("code").toLowerCase().indexOf(inputVal.toLowerCase()) > -1; | ||
determineSuggestions: function(options, input) { | ||
var list = options.filter(function(item) { | ||
return item.get("code").toLowerCase().indexOf(input.toLowerCase()) > -1; | ||
}); | ||
}.property("inputVal", "options.@each"), | ||
optionsToMatch: function() { | ||
var caseInsensitiveOptions = []; | ||
this.get("options").forEach(function(item) { | ||
var value = item.get("code"); | ||
caseInsensitiveOptions.push(value); | ||
caseInsensitiveOptions.push(value.toLowerCase()); | ||
}); | ||
return caseInsensitiveOptions; | ||
}.property("options.@each") | ||
return Ember.A(list); | ||
} | ||
}); | ||
@@ -52,0 +43,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
277
14937
136