Skip to content
Permalink
Browse files

Autocomplete: Added response event. Fixes #6777 - Autocomplete callba…

…ck when search is complete.
  • Loading branch information...
scottgonzalez committed Mar 22, 2011
1 parent de5a98e commit e7991e33f3c5d20d6efdb18654859175ef5cac68
Showing with 33 additions and 12 deletions.
  1. +29 −11 tests/unit/autocomplete/autocomplete_events.js
  2. +4 −1 ui/jquery.ui.autocomplete.js
@@ -9,41 +9,50 @@ module("autocomplete: events", {
}
});

var data = ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl"];
var data = [ "Clojure", "COBOL", "ColdFusion", "Java", "JavaScript", "Scala", "Scheme" ];

test("all events", function() {
expect(12);
expect(14);
var ac = $("#autocomplete").autocomplete({
autoFocus: false,
delay: 0,
source: data,
search: function(event) {
same(event.type, "autocompletesearch");
},
response: function(event, ui) {
same(event.type, "autocompleteresponse");
same(ui.content, [
{ label: "Clojure", value: "Clojure" },
{ label: "Java", value: "Java" },
{ label: "JavaScript", value: "JavaScript" }
]);
ui.content.splice( 0, 1 );
},
open: function(event) {
same(event.type, "autocompleteopen");
},
focus: function(event, ui) {
same(event.type, "autocompletefocus");
same(ui.item, {label:"java", value:"java"});
same(ui.item, {label:"Java", value:"Java"});
},
close: function(event) {
same(event.type, "autocompleteclose");
same( $(".ui-menu:visible").length, 0 );
},
select: function(event, ui) {
same(event.type, "autocompleteselect");
same(ui.item, {label:"java", value:"java"});
same(ui.item, {label:"Java", value:"Java"});
},
change: function(event, ui) {
same(event.type, "autocompletechange");
same(ui.item, {label:"java", value:"java"});
same(ui.item, {label:"Java", value:"Java"});
same( $(".ui-menu:visible").length, 0 );
start();
}
});
stop();
ac.focus().val("ja").keydown();
ac.focus().val("j").keydown();
setTimeout(function() {
same( $(".ui-menu:visible").length, 1 );
ac.simulate("keydown", { keyCode: $.ui.keyCode.DOWN });
@@ -55,38 +64,47 @@ test("all events", function() {
});

test("all events - contenteditable", function() {
expect(12);
expect(14);
var ac = $("#autocomplete-contenteditable").autocomplete({
autoFocus: false,
delay: 0,
source: data,
search: function(event) {
same(event.type, "autocompletesearch");
},
response: function(event, ui) {
same(event.type, "autocompleteresponse");
same(ui.content, [
{ label: "Clojure", value: "Clojure" },
{ label: "Java", value: "Java" },
{ label: "JavaScript", value: "JavaScript" }
]);
ui.content.splice( 0, 1 );
},
open: function(event) {
same(event.type, "autocompleteopen");
},
focus: function(event, ui) {
same(event.type, "autocompletefocus");
same(ui.item, {label:"java", value:"java"});
same(ui.item, {label:"Java", value:"Java"});
},
close: function(event) {
same(event.type, "autocompleteclose");
same( $(".ui-menu:visible").length, 0 );
},
select: function(event, ui) {
same(event.type, "autocompleteselect");
same(ui.item, {label:"java", value:"java"});
same(ui.item, {label:"Java", value:"Java"});
},
change: function(event, ui) {
same(event.type, "autocompletechange");
same(ui.item, {label:"java", value:"java"});
same(ui.item, {label:"Java", value:"Java"});
same( $(".ui-menu:visible").length, 0 );
start();
}
});
stop();
ac.focus().text("ja").keydown();
ac.focus().text("j").keydown();
setTimeout(function() {
same( $(".ui-menu:visible").length, 1 );
ac.simulate("keydown", { keyCode: $.ui.keyCode.DOWN });
@@ -307,8 +307,11 @@ $.widget( "ui.autocomplete", {
},

_response: function( content ) {
if ( !this.options.disabled && content && content.length ) {
if ( content ) {
content = this._normalize( content );
}
this._trigger( "response", null, { content: content } );
if ( !this.options.disabled && content && content.length ) {
this._suggest( content );
this._trigger( "open" );
} else {

1 comment on commit e7991e3

@koen-serry

This comment has been minimized.

Copy link

commented on e7991e3 Apr 22, 2011

What is the purpose of having both a label and a value if they are always the same. And if you'd want to use them that is shows the value after selecting the label

Please sign in to comment.
You can’t perform that action at this time.