diff --git a/demo.html b/demo.html
index 25c930e..b65c7c8 100644
--- a/demo.html
+++ b/demo.html
@@ -345,33 +345,34 @@
Demo Try searching for: account,
}, 2000);
},
valueMatches : function(category, searchTerm, callback) {
+ var values;
switch (category) {
- case 'account':
- callback([
+ case 'account':
+ values = [
{ value: '1-amanda', label: 'Amanda' },
{ value: '2-aron', label: 'Aron' },
{ value: '3-eric', label: 'Eric' },
{ value: '4-jeremy', label: 'Jeremy' },
{ value: '5-samuel', label: 'Samuel' },
{ value: '6-scott', label: 'Scott' }
- ]);
+ ];
break;
case 'filter':
- callback(['published', 'unpublished', 'draft']);
+ values = ['published', 'unpublished', 'draft'];
break;
case 'access':
- callback(['public', 'private', 'protected']);
+ values = ['public', 'private', 'protected'];
break;
case 'title':
- callback([
+ values = [
'Pentagon Papers',
'CoffeeScript Manual',
'Laboratory for Object Oriented Thinking',
'A Repository Grows in Brooklyn'
- ]);
+ ];
break;
case 'city':
- callback([
+ values = [
'Cleveland',
'New York City',
'Brooklyn',
@@ -386,10 +387,10 @@ Demo Try searching for: account,
'Portland',
'Chicago',
'Boston'
- ])
+ ];
break;
case 'state':
- callback([
+ values = [
"Alabama", "Alaska", "Arizona", "Arkansas", "California",
"Colorado", "Connecticut", "Delaware", "District of Columbia", "Florida",
"Georgia", "Guam", "Hawaii", "Idaho", "Illinois",
@@ -401,10 +402,10 @@ Demo Try searching for: account,
"Puerto Rico", "Rhode Island", "South Carolina", "South Dakota", "Tennessee",
"Texas", "Utah", "Vermont", "Virginia", "Virgin Islands",
"Washington", "West Virginia", "Wisconsin", "Wyoming"
- ]);
+ ];
break
case 'country':
- callback([
+ values = [
"China", "India", "United States", "Indonesia", "Brazil",
"Pakistan", "Bangladesh", "Nigeria", "Russia", "Japan",
"Mexico", "Philippines", "Vietnam", "Ethiopia", "Egypt",
@@ -428,9 +429,10 @@ Demo Try searching for: account,
"Togo", "Libya", "Jordan", "Paraguay", "Laos",
"El Salvador", "Sierra Leone", "Nicaragua", "Kyrgyzstan", "Denmark",
"Slovakia", "Finland", "Eritrea", "Turkmenistan"
- ]);
+ ];
break;
}
+ callback(values);
},
facetMatches : function(callback) {
callback([
diff --git a/lib/js/utils/search_parser.js b/lib/js/utils/search_parser.js
index edea47c..098a984 100644
--- a/lib/js/utils/search_parser.js
+++ b/lib/js/utils/search_parser.js
@@ -40,11 +40,14 @@ VS.app.SearchParser = {
value = field;
query = VS.utils.inflector.trim(query.replace(value, ''));
}
+
+ var label = null; // You want the values from search_facet.js:autocompleteValues.
if (category && value) {
var searchFacet = new VS.model.SearchFacet({
category : category,
value : VS.utils.inflector.trim(value),
+ label : label,
app : instance
});
facets.push(searchFacet);
diff --git a/lib/js/views/search_box.js b/lib/js/views/search_box.js
index aef16ba..6d2b723 100644
--- a/lib/js/views/search_box.js
+++ b/lib/js/views/search_box.js
@@ -95,10 +95,12 @@ VS.ui.SearchBox = Backbone.View.extend({
category = VS.utils.inflector.trim(category);
initialQuery = VS.utils.inflector.trim(initialQuery || '');
if (!category) return;
-
+ var label = "Yatta";
+
var model = new VS.model.SearchFacet({
category : category,
value : initialQuery || '',
+ label : label,
app : this.app
});
this.app.searchQuery.add(model, {at: position});
diff --git a/lib/js/views/search_facet.js b/lib/js/views/search_facet.js
index f81b132..a905dab 100644
--- a/lib/js/views/search_facet.js
+++ b/lib/js/views/search_facet.js
@@ -36,7 +36,7 @@ VS.ui.SearchFacet = Backbone.View.extend({
this.setMode('not', 'editing');
this.setMode('not', 'selected');
this.box = this.$('input');
- this.box.val(this.model.get('value'));
+ this.box.val(this.model.get('label'));
this.box.bind('blur', this.deferDisableEdit);
// Handle paste events with `propertychange`
this.box.bind('input propertychange', this.keydown);
@@ -74,7 +74,7 @@ VS.ui.SearchFacet = Backbone.View.extend({
select : _.bind(function(e, ui) {
e.preventDefault();
var originalValue = this.model.get('value');
- this.set(ui.item.value);
+ this.set(ui.item.value, ui.item.label);
if (originalValue != ui.item.value || this.box.val() != ui.item.value) {
this.search(e);
}
@@ -171,9 +171,9 @@ VS.ui.SearchFacet = Backbone.View.extend({
},
// Sets the facet's model's value.
- set : function(value) {
+ set : function(value, label) {
if (!value) return;
- this.model.set({'value': value});
+ this.model.set({'value': value, 'label': label});
},
// Before the searchBox performs a search, we need to close the
@@ -197,7 +197,7 @@ VS.ui.SearchFacet = Backbone.View.extend({
this.setMode('is', 'editing');
this.deselectFacet();
if (this.box.val() == '') {
- this.box.val(this.model.get('value'));
+ this.box.val(this.model.get('label'));
}
}
@@ -234,7 +234,7 @@ VS.ui.SearchFacet = Backbone.View.extend({
// the autocomplete menu.
disableEdit : function() {
var newFacetQuery = VS.utils.inflector.trim(this.box.val());
- if (newFacetQuery != this.model.get('value')) {
+ if (newFacetQuery != this.model.get('value') && newFacetQuery != this.model.get('label')) {
this.set(newFacetQuery);
}
this.flags.canClose = false;