Skip to content

Commit

Permalink
Merge branch 'topics-bug-3492'
Browse files Browse the repository at this point in the history
  • Loading branch information
ahaith committed May 6, 2016
2 parents 7309290 + 5330782 commit dc81c39
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion static/js/form-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ $(function() {
var valueKey = $(mainInput).data('valueKey');
var labelKey = $(mainInput).data('labelKey');
//use the supplied value, else retrieve from document data, else fetch from bloodhound storage
suggestion = suggestion || $(input).data('suggestion') || getSuggestionById(mainInput, $(input).prop('value'), valueKey);
var value = $(input).prop('value');
suggestion = suggestion || $(input).data('suggestion') || getSuggestionById(mainInput, value, valueKey);
if(!suggestion) {
//couldn't retrieve. Perhaps an error in the search endpoint. Just show the id
console.error("Couldn't retrieve value for typeahead. ID was ", value);
suggestion = {};
suggestion[valueKey] = value;
suggestion[labelKey] = "(" + value + ")";
}
var t = _.template('<div data-id="<%= ' + valueKey + ' %>" class="list-group-item list-group-item-info fade in"><a href="#"><span class="glyphicon glyphicon-remove"></span></a><%= ' + labelKey + ' %></div>');
var item = $(t(suggestion)).insertAfter(input);
$('a', item).click(removeItem).click(function() { $(mainInput).show().focus().val('') });
Expand Down

0 comments on commit dc81c39

Please sign in to comment.