mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Autocomplete: Added response event. Fixes #6777 - Autocomplete callback when search is complete.
This commit is contained in:
parent
de5a98e7bc
commit
e7991e33f3
@ -9,10 +9,10 @@ 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() {
|
test("all events", function() {
|
||||||
expect(12);
|
expect(14);
|
||||||
var ac = $("#autocomplete").autocomplete({
|
var ac = $("#autocomplete").autocomplete({
|
||||||
autoFocus: false,
|
autoFocus: false,
|
||||||
delay: 0,
|
delay: 0,
|
||||||
@ -20,12 +20,21 @@ test("all events", function() {
|
|||||||
search: function(event) {
|
search: function(event) {
|
||||||
same(event.type, "autocompletesearch");
|
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) {
|
open: function(event) {
|
||||||
same(event.type, "autocompleteopen");
|
same(event.type, "autocompleteopen");
|
||||||
},
|
},
|
||||||
focus: function(event, ui) {
|
focus: function(event, ui) {
|
||||||
same(event.type, "autocompletefocus");
|
same(event.type, "autocompletefocus");
|
||||||
same(ui.item, {label:"java", value:"java"});
|
same(ui.item, {label:"Java", value:"Java"});
|
||||||
},
|
},
|
||||||
close: function(event) {
|
close: function(event) {
|
||||||
same(event.type, "autocompleteclose");
|
same(event.type, "autocompleteclose");
|
||||||
@ -33,17 +42,17 @@ test("all events", function() {
|
|||||||
},
|
},
|
||||||
select: function(event, ui) {
|
select: function(event, ui) {
|
||||||
same(event.type, "autocompleteselect");
|
same(event.type, "autocompleteselect");
|
||||||
same(ui.item, {label:"java", value:"java"});
|
same(ui.item, {label:"Java", value:"Java"});
|
||||||
},
|
},
|
||||||
change: function(event, ui) {
|
change: function(event, ui) {
|
||||||
same(event.type, "autocompletechange");
|
same(event.type, "autocompletechange");
|
||||||
same(ui.item, {label:"java", value:"java"});
|
same(ui.item, {label:"Java", value:"Java"});
|
||||||
same( $(".ui-menu:visible").length, 0 );
|
same( $(".ui-menu:visible").length, 0 );
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
stop();
|
stop();
|
||||||
ac.focus().val("ja").keydown();
|
ac.focus().val("j").keydown();
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
same( $(".ui-menu:visible").length, 1 );
|
same( $(".ui-menu:visible").length, 1 );
|
||||||
ac.simulate("keydown", { keyCode: $.ui.keyCode.DOWN });
|
ac.simulate("keydown", { keyCode: $.ui.keyCode.DOWN });
|
||||||
@ -55,7 +64,7 @@ test("all events", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("all events - contenteditable", function() {
|
test("all events - contenteditable", function() {
|
||||||
expect(12);
|
expect(14);
|
||||||
var ac = $("#autocomplete-contenteditable").autocomplete({
|
var ac = $("#autocomplete-contenteditable").autocomplete({
|
||||||
autoFocus: false,
|
autoFocus: false,
|
||||||
delay: 0,
|
delay: 0,
|
||||||
@ -63,12 +72,21 @@ test("all events - contenteditable", function() {
|
|||||||
search: function(event) {
|
search: function(event) {
|
||||||
same(event.type, "autocompletesearch");
|
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) {
|
open: function(event) {
|
||||||
same(event.type, "autocompleteopen");
|
same(event.type, "autocompleteopen");
|
||||||
},
|
},
|
||||||
focus: function(event, ui) {
|
focus: function(event, ui) {
|
||||||
same(event.type, "autocompletefocus");
|
same(event.type, "autocompletefocus");
|
||||||
same(ui.item, {label:"java", value:"java"});
|
same(ui.item, {label:"Java", value:"Java"});
|
||||||
},
|
},
|
||||||
close: function(event) {
|
close: function(event) {
|
||||||
same(event.type, "autocompleteclose");
|
same(event.type, "autocompleteclose");
|
||||||
@ -76,17 +94,17 @@ test("all events - contenteditable", function() {
|
|||||||
},
|
},
|
||||||
select: function(event, ui) {
|
select: function(event, ui) {
|
||||||
same(event.type, "autocompleteselect");
|
same(event.type, "autocompleteselect");
|
||||||
same(ui.item, {label:"java", value:"java"});
|
same(ui.item, {label:"Java", value:"Java"});
|
||||||
},
|
},
|
||||||
change: function(event, ui) {
|
change: function(event, ui) {
|
||||||
same(event.type, "autocompletechange");
|
same(event.type, "autocompletechange");
|
||||||
same(ui.item, {label:"java", value:"java"});
|
same(ui.item, {label:"Java", value:"Java"});
|
||||||
same( $(".ui-menu:visible").length, 0 );
|
same( $(".ui-menu:visible").length, 0 );
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
stop();
|
stop();
|
||||||
ac.focus().text("ja").keydown();
|
ac.focus().text("j").keydown();
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
same( $(".ui-menu:visible").length, 1 );
|
same( $(".ui-menu:visible").length, 1 );
|
||||||
ac.simulate("keydown", { keyCode: $.ui.keyCode.DOWN });
|
ac.simulate("keydown", { keyCode: $.ui.keyCode.DOWN });
|
||||||
|
5
ui/jquery.ui.autocomplete.js
vendored
5
ui/jquery.ui.autocomplete.js
vendored
@ -307,8 +307,11 @@ $.widget( "ui.autocomplete", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_response: function( content ) {
|
_response: function( content ) {
|
||||||
if ( !this.options.disabled && content && content.length ) {
|
if ( content ) {
|
||||||
content = this._normalize( content );
|
content = this._normalize( content );
|
||||||
|
}
|
||||||
|
this._trigger( "response", null, { content: content } );
|
||||||
|
if ( !this.options.disabled && content && content.length ) {
|
||||||
this._suggest( content );
|
this._suggest( content );
|
||||||
this._trigger( "open" );
|
this._trigger( "open" );
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user