Skip to content

Commit

Permalink
Fix yourlabs#244: Added ajax loading in input.autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
jpic committed Jan 27, 2014
1 parent 7fd96b1 commit a231c0e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions autocomplete_light/static/autocomplete_light/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,8 @@ yourlabs.Autocomplete.prototype.fetch = function() {

// Wrapped ajax call to use with setTimeout in fetch().
yourlabs.Autocomplete.prototype.makeXhr = function() {
this.input.addClass('xhr-pending');

this.xhr = $.ajax(this.url, {
type: "GET",
data: this.data,
Expand All @@ -569,6 +571,8 @@ yourlabs.Autocomplete.prototype.makeXhr = function() {

// Callback for the ajax response.
yourlabs.Autocomplete.prototype.fetchComplete = function(jqXHR, textStatus) {
this.input.removeClass('xhr-pending');

if (this.xhr == jqXHR) this.xhr = false;
if (textStatus == 'abort') return;
this.show(jqXHR.responseText);
Expand Down
6 changes: 6 additions & 0 deletions autocomplete_light/static/autocomplete_light/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ input.autocomplete {
vertical-align: top;
}

input.autocomplete.xhr-pending {
background-image: url('xhr-pending.gif');
background-repeat: no-repeat;
background-position: right;
}

.autocomplete-light-widget.yourlabs-autocomplete {
position: absolute;
top: 100%;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions autocomplete_light/tests/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ def test_autocomplete_shows_up(self):
def test_autocomplete_has_four_choices(self):
self.assertEqual(4, len(self.autocomplete_choices()))

def test_xhr_pending(self):
self.selenium.find_element_by_css_selector(
'input.xhr-pending[name=%s-autocomplete]' % self.autocomplete_name)

self.selenium.find_element_by_css_selector(
'input:not(.xhr-pending)[name=%s-autocomplete]' % self.autocomplete_name)


class SelectChoiceInEmptyFormTestCase(WidgetTestCase):
def setup_test_case(self):
Expand Down

0 comments on commit a231c0e

Please sign in to comment.