Autocomplete: Style updates

Ref #14246
Ref gh-1588
This commit is contained in:
Alexander Schmitz 2015-08-21 00:11:54 -04:00
parent a6499c0dee
commit 8029cc94e1
6 changed files with 209 additions and 206 deletions

View File

@ -22,7 +22,7 @@ common.testWidget( "autocomplete", {
},
source: null,
// callbacks
// Callbacks
change: null,
close: null,
create: null,
@ -32,6 +32,6 @@ common.testWidget( "autocomplete", {
search: null,
select: null
}
});
} );
} );

View File

@ -12,15 +12,15 @@ test( "markup structure", function( assert ) {
assert.hasClasses( element, "ui-autocomplete-input" );
assert.hasClasses( menu, "ui-autocomplete ui-widget ui-widget-content" );
});
} );
test( "prevent form submit on enter when menu is active", function() {
expect( 2 );
var event,
element = $( "#autocomplete" )
.autocomplete({
.autocomplete( {
source: [ "java", "javascript" ]
})
} )
.val( "ja" )
.autocomplete( "search" ),
menu = element.autocomplete( "widget" );
@ -35,16 +35,16 @@ test( "prevent form submit on enter when menu is active", function() {
event.keyCode = $.ui.keyCode.ENTER;
element.trigger( event );
ok( event.isDefaultPrevented(), "default action is prevented" );
});
} );
test( "allow form submit on enter when menu is not active", function() {
expect( 1 );
var event,
element = $( "#autocomplete" )
.autocomplete({
.autocomplete( {
autoFocus: false,
source: [ "java", "javascript" ]
})
} )
.val( "ja" )
.autocomplete( "search" );
@ -52,90 +52,90 @@ test( "allow form submit on enter when menu is not active", function() {
event.keyCode = $.ui.keyCode.ENTER;
element.trigger( event );
ok( !event.isDefaultPrevented(), "default action is prevented" );
});
} );
(function() {
( function() {
test( "up arrow invokes search - input", function() {
arrowsInvokeSearch( "#autocomplete", true, true );
});
} );
test( "down arrow invokes search - input", function() {
arrowsInvokeSearch( "#autocomplete", false, true );
});
} );
test( "up arrow invokes search - textarea", function() {
arrowsInvokeSearch( "#autocomplete-textarea", true, false );
});
} );
test( "down arrow invokes search - textarea", function() {
arrowsInvokeSearch( "#autocomplete-textarea", false, false );
});
} );
test( "up arrow invokes search - contenteditable", function() {
arrowsInvokeSearch( "#autocomplete-contenteditable", true, false );
});
} );
test( "down arrow invokes search - contenteditable", function() {
arrowsInvokeSearch( "#autocomplete-contenteditable", false, false );
});
} );
test( "up arrow moves focus - input", function() {
arrowsMoveFocus( "#autocomplete", true );
});
} );
test( "down arrow moves focus - input", function() {
arrowsMoveFocus( "#autocomplete", false );
});
} );
test( "up arrow moves focus - textarea", function() {
arrowsMoveFocus( "#autocomplete-textarea", true );
});
} );
test( "down arrow moves focus - textarea", function() {
arrowsMoveFocus( "#autocomplete-textarea", false );
});
} );
test( "up arrow moves focus - contenteditable", function() {
arrowsMoveFocus( "#autocomplete-contenteditable", true );
});
} );
test( "down arrow moves focus - contenteditable", function() {
arrowsMoveFocus( "#autocomplete-contenteditable", false );
});
} );
test( "up arrow moves cursor - input", function() {
arrowsNavigateElement( "#autocomplete", true, false );
});
} );
test( "down arrow moves cursor - input", function() {
arrowsNavigateElement( "#autocomplete", false, false );
});
} );
test( "up arrow moves cursor - textarea", function() {
arrowsNavigateElement( "#autocomplete-textarea", true, true );
});
} );
test( "down arrow moves cursor - textarea", function() {
arrowsNavigateElement( "#autocomplete-textarea", false, true );
});
} );
test( "up arrow moves cursor - contenteditable", function() {
arrowsNavigateElement( "#autocomplete-contenteditable", true, true );
});
} );
test( "down arrow moves cursor - contenteditable", function() {
arrowsNavigateElement( "#autocomplete-contenteditable", false, true );
});
} );
function arrowsInvokeSearch( id, isKeyUp, shouldMove ) {
expect( 1 );
var didMove = false,
element = $( id ).autocomplete({
element = $( id ).autocomplete( {
source: [ "a" ],
delay: 0,
minLength: 0
});
} );
element.autocomplete( "instance" )._move = function() {
didMove = true;
};
@ -146,11 +146,11 @@ test( "allow form submit on enter when menu is not active", function() {
function arrowsMoveFocus( id, isKeyUp ) {
expect( 1 );
var element = $( id ).autocomplete({
var element = $( id ).autocomplete( {
source: [ "a" ],
delay: 0,
minLength: 0
});
} );
element.autocomplete( "instance" )._move = function() {
ok( true, "repsond to arrow" );
};
@ -162,25 +162,25 @@ test( "allow form submit on enter when menu is not active", function() {
expect( 1 );
var didMove = false,
element = $( id ).autocomplete({
element = $( id ).autocomplete( {
source: [ "a" ],
delay: 0,
minLength: 0
});
} );
element.on( "keypress", function( e ) {
didMove = !e.isDefaultPrevented();
});
} );
element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } );
element.simulate( "keypress" );
equal( didMove, shouldMove, "respond to arrow" );
}
})();
} )();
asyncTest( "past end of menu in multiline autocomplete", function() {
expect( 2 );
var customVal = "custom value",
element = $( "#autocomplete-contenteditable" ).autocomplete({
element = $( "#autocomplete-contenteditable" ).autocomplete( {
delay: 0,
source: [ "javascript" ],
focus: function( event, ui ) {
@ -188,25 +188,25 @@ asyncTest( "past end of menu in multiline autocomplete", function() {
$( this ).text( customVal );
event.preventDefault();
}
});
} );
element
.simulate( "focus" )
.autocomplete( "search", "ja" );
setTimeout(function() {
setTimeout( function() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal( element.text(), customVal );
start();
});
});
} );
} );
asyncTest( "ESCAPE in multiline autocomplete", function() {
expect( 2 );
var customVal = "custom value",
element = $( "#autocomplete-contenteditable" ).autocomplete({
element = $( "#autocomplete-contenteditable" ).autocomplete( {
delay: 0,
source: [ "javascript" ],
focus: function( event, ui ) {
@ -214,38 +214,38 @@ asyncTest( "ESCAPE in multiline autocomplete", function() {
$( this ).text( customVal );
event.preventDefault();
}
});
} );
element
.simulate( "focus" )
.autocomplete( "search", "ja" );
setTimeout(function() {
setTimeout( function() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
equal( element.text(), customVal );
start();
});
});
} );
} );
asyncTest( "handle race condition", function() {
expect( 3 );
var count = 0,
element = $( "#autocomplete" ).autocomplete({
element = $( "#autocomplete" ).autocomplete( {
source: function( request, response ) {
count++;
if ( request.term.length === 1 ) {
equal( count, 1, "request with 1 character is first" );
setTimeout(function() {
response([ "one" ]);
setTimeout( function() {
response( [ "one" ] );
setTimeout( checkResults );
});
} );
return;
}
equal( count, 2, "request with 2 characters is second" );
response([ "two" ]);
response( [ "two" ] );
}
});
} );
element.autocomplete( "search", "a" );
element.autocomplete( "search", "ab" );
@ -255,41 +255,41 @@ asyncTest( "handle race condition", function() {
"correct results displayed" );
start();
}
});
} );
asyncTest( "simultaneous searches (#9334)", function() {
expect( 2 );
var element = $( "#autocomplete" ).autocomplete({
var element = $( "#autocomplete" ).autocomplete( {
source: function( request, response ) {
setTimeout(function() {
response([ request.term ]);
});
setTimeout( function() {
response( [ request.term ] );
} );
},
response: function() {
ok( true, "response from first instance" );
}
}),
element2 = $( "#autocomplete-textarea" ).autocomplete({
} ),
element2 = $( "#autocomplete-textarea" ).autocomplete( {
source: function( request, response ) {
setTimeout(function() {
response([ request.term ]);
});
setTimeout( function() {
response( [ request.term ] );
} );
},
response: function() {
ok( true, "response from second instance" );
start();
}
});
} );
element.autocomplete( "search", "test" );
element2.autocomplete( "search", "test" );
});
} );
test( "ARIA", function() {
expect( 13 );
var element = $( "#autocomplete" ).autocomplete({
var element = $( "#autocomplete" ).autocomplete( {
source: [ "java", "javascript" ]
}),
} ),
liveRegion = element.autocomplete( "instance" ).liveRegion;
equal( liveRegion.children().length, 0, "Empty live region on create" );
@ -311,7 +311,7 @@ test( "ARIA", function() {
element.one( "autocompletefocus", function( event ) {
event.preventDefault();
});
} );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal( liveRegion.children().filter( ":visible" ).text(), "javascript",
"Live region updated when default focus is prevented" );
@ -335,7 +335,7 @@ test( "ARIA", function() {
element.autocomplete( "destroy" );
equal( liveRegion.parent().length, 0,
"The liveRegion should be detached after destroy" );
});
} );
test( "ARIA, aria-label announcement", function() {
expect( 1 );
@ -345,27 +345,27 @@ test( "ARIA, aria-label announcement", function() {
$.each( items, function( index, item ) {
that._renderItemData( ul, item )
.attr( "aria-label", item.category + " : " + item.label );
});
} );
}
});
var element = $( "#autocomplete" ).catcomplete({
} );
var element = $( "#autocomplete" ).catcomplete( {
source: [ { label: "anders andersson", category: "People" } ]
}),
} ),
liveRegion = element.catcomplete( "instance" ).liveRegion;
element.catcomplete( "search", "a" );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal( liveRegion.children().filter( ":visible" ).text(), "People : anders andersson",
"Live region changed on keydown to announce the highlighted value's aria-label attribute" );
});
} );
test( "ARIA, init on detached input", function() {
expect( 1 );
var element = $( "<input>" ).autocomplete({
var element = $( "<input>" ).autocomplete( {
source: [ "java", "javascript" ]
}),
} ),
liveRegion = element.autocomplete( "instance" ).liveRegion;
equal( liveRegion.parent().length, 1, "liveRegion must have a parent" );
});
} );
test( ".replaceWith() (#9172)", function() {
expect( 1 );
@ -375,27 +375,27 @@ test( ".replaceWith() (#9172)", function() {
parent = element.parent();
element.replaceWith( replacement );
equal( parent.html().toLowerCase(), replacement );
});
} );
asyncTest( "Search if the user retypes the same value (#7434)", function() {
expect( 3 );
var element = $( "#autocomplete" ).autocomplete({
var element = $( "#autocomplete" ).autocomplete( {
source: [ "java", "javascript" ],
delay: 0
}),
} ),
menu = element.autocomplete( "instance" ).menu.element;
element.val( "j" ).simulate( "keydown" );
setTimeout(function() {
setTimeout( function() {
ok( menu.is( ":visible" ), "menu displays initially" );
element.trigger( "blur" );
ok( !menu.is( ":visible" ), "menu hidden after blur" );
element.val( "j" ).simulate( "keydown" );
setTimeout(function() {
setTimeout( function() {
ok( menu.is( ":visible" ), "menu displays after typing the same value" );
start();
});
});
});
} );
} );
} );
} );

View File

@ -7,7 +7,7 @@ module( "autocomplete: events" );
var data = [ "Clojure", "COBOL", "ColdFusion", "Java", "JavaScript", "Scala", "Scheme" ];
$.each([
$.each( [
{
type: "input",
selector: "#autocomplete",
@ -27,7 +27,7 @@ $.each([
asyncTest( "all events - " + settings.type, function() {
expect( 13 );
var element = $( settings.selector )
.autocomplete({
.autocomplete( {
autoFocus: false,
delay: 0,
source: data,
@ -63,40 +63,41 @@ $.each([
ok( menu.is( ":hidden" ), "menu closed on change" );
start();
}
}),
} ),
menu = element.autocomplete( "widget" );
element.simulate( "focus" )[ settings.valueMethod ]( "j" ).trigger( "keydown" );
setTimeout(function() {
setTimeout( function() {
ok( menu.is( ":visible" ), "menu is visible after delay" );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
// blur must be async for IE to handle it properly
setTimeout(function() {
// Blur must be async for IE to handle it properly
setTimeout( function() {
element.simulate( "blur" );
});
});
});
});
} );
} );
} );
} );
asyncTest( "change without selection", function() {
expect( 1 );
var element = $( "#autocomplete" ).autocomplete({
var element = $( "#autocomplete" ).autocomplete( {
delay: 0,
source: data,
change: function( event, ui ) {
strictEqual( ui.item, null );
start();
}
});
} );
element.triggerHandler( "focus" );
element.val( "ja" ).triggerHandler( "blur" );
});
} );
asyncTest( "cancel search", function() {
expect( 6 );
var first = true,
element = $( "#autocomplete" ).autocomplete({
element = $( "#autocomplete" ).autocomplete( {
delay: 0,
source: data,
search: function() {
@ -110,76 +111,76 @@ asyncTest( "cancel search", function() {
open: function() {
ok( true, "menu opened" );
}
}),
} ),
menu = element.autocomplete( "widget" );
element.val( "ja" ).trigger( "keydown" );
setTimeout(function() {
setTimeout( function() {
ok( menu.is( ":hidden" ), "menu is hidden after first search" );
element.val( "java" ).trigger( "keydown" );
setTimeout(function() {
setTimeout( function() {
ok( menu.is( ":visible" ), "menu is visible after second search" );
equal( menu.find( ".ui-menu-item" ).length, 2, "# of menu items" );
start();
});
});
});
} );
} );
} );
asyncTest( "cancel focus", function() {
expect( 1 );
var customVal = "custom value",
element = $( "#autocomplete" ).autocomplete({
element = $( "#autocomplete" ).autocomplete( {
delay: 0,
source: data,
focus: function() {
$( this ).val( customVal );
return false;
}
});
} );
element.val( "ja" ).trigger( "keydown" );
setTimeout(function() {
setTimeout( function() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal( element.val(), customVal );
start();
});
});
} );
} );
asyncTest( "cancel select", function() {
expect( 1 );
var customVal = "custom value",
element = $( "#autocomplete" ).autocomplete({
element = $( "#autocomplete" ).autocomplete( {
delay: 0,
source: data,
select: function() {
$( this ).val( customVal );
return false;
}
});
} );
element.val( "ja" ).trigger( "keydown" );
setTimeout(function() {
setTimeout( function() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
equal( element.val(), customVal );
start();
});
});
} );
} );
asyncTest( "blur during remote search", function() {
expect( 1 );
var ac = $( "#autocomplete" ).autocomplete({
var ac = $( "#autocomplete" ).autocomplete( {
delay: 0,
source: function( request, response ) {
ok( true, "trigger request" );
ac.simulate( "blur" );
setTimeout(function() {
response([ "result" ]);
setTimeout( function() {
response( [ "result" ] );
start();
}, 25);
}, 25 );
},
open: function() {
ok( false, "opened after a blur" );
}
});
} );
ac.val( "ro" ).trigger( "keydown" );
});
} );
} );

View File

@ -9,16 +9,16 @@ test( "destroy", function( assert ) {
expect( 1 );
assert.domEqual( "#autocomplete", function() {
$( "#autocomplete" ).autocomplete().autocomplete( "destroy" );
});
});
} );
} );
test( "search, close", function() {
expect( 6 );
var data = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl" ],
element = $( "#autocomplete" ).autocomplete({
element = $( "#autocomplete" ).autocomplete( {
source: data,
minLength: 0
}),
} ),
menu = element.autocomplete( "widget" );
ok( menu.is( ":hidden" ), "menu is hidden on init" );
@ -35,7 +35,7 @@ test( "search, close", function() {
element.autocomplete( "close" );
ok( menu.is( ":hidden" ), "menu is hidden after close" );
});
} );
test( "widget", function( assert ) {
expect( 2 );
@ -43,6 +43,6 @@ test( "widget", function( assert ) {
widgetElement = element.autocomplete( "widget" );
equal( widgetElement.length, 1, "one element" );
assert.hasClasses( widgetElement, "ui-menu" );
});
} );
} );

View File

@ -14,16 +14,16 @@ test( "appendTo: null", function() {
equal( element.autocomplete( "widget" ).parent()[ 0 ], document.body,
"defaults to body" );
element.autocomplete( "destroy" );
});
} );
test( "appendTo: explicit", function() {
expect( 6 );
var detached = $( "<div>" ),
element = $( "#autocomplete" );
element.autocomplete({
element.autocomplete( {
appendTo: ".autocomplete-wrap"
});
} );
equal( element.autocomplete( "widget" ).parent()[ 0 ],
$( "#autocomplete-wrap1" )[ 0 ], "first found element" );
equal( $( "#autocomplete-wrap2 .ui-autocomplete" ).length, 0,
@ -35,16 +35,16 @@ test( "appendTo: explicit", function() {
$( "#autocomplete-wrap1" )[ 0 ], "modified after init" );
element.autocomplete( "destroy" );
element.autocomplete({
element.autocomplete( {
appendTo: detached
});
} );
equal( element.autocomplete( "widget" ).parent()[ 0 ], detached[ 0 ],
"detached jQuery object" );
element.autocomplete( "destroy" );
element.autocomplete({
element.autocomplete( {
appendTo: detached[ 0 ]
});
} );
equal( element.autocomplete( "widget" ).parent()[ 0 ], detached[ 0 ],
"detached DOM element" );
element.autocomplete( "destroy" );
@ -53,7 +53,7 @@ test( "appendTo: explicit", function() {
equal( element.autocomplete( "widget" ).parent()[ 0 ], detached[ 0 ],
"detached DOM element via option()" );
element.autocomplete( "destroy" );
});
} );
test( "appendTo: ui-front", function() {
expect( 2 );
@ -65,15 +65,15 @@ test( "appendTo: ui-front", function() {
$( "#autocomplete-wrap2" )[ 0 ], "null, inside .ui-front" );
element.autocomplete( "destroy" );
element.autocomplete({
element.autocomplete( {
appendTo: $()
});
} );
equal( element.autocomplete( "widget" ).parent()[ 0 ],
$( "#autocomplete-wrap2" )[ 0 ], "empty jQuery object, inside .ui-front" );
});
} );
function autoFocusTest( afValue, focusedLength ) {
var element = $( "#autocomplete" ).autocomplete({
var element = $( "#autocomplete" ).autocomplete( {
autoFocus: afValue,
delay: 0,
source: data,
@ -83,10 +83,10 @@ function autoFocusTest( afValue, focusedLength ) {
.find( ".ui-menu-item-wrapper.ui-state-active" )
.length,
focusedLength,
"first item is " + (afValue ? "" : "not") + " auto focused" );
"first item is " + ( afValue ? "" : "not" ) + " auto focused" );
start();
}
});
} );
element.val( "ja" ).trigger( "keydown" );
stop();
}
@ -94,36 +94,36 @@ function autoFocusTest( afValue, focusedLength ) {
test( "autoFocus: false", function() {
expect( 1 );
autoFocusTest( false, 0 );
});
} );
test( "autoFocus: true", function() {
expect( 1 );
autoFocusTest( true, 1 );
});
} );
asyncTest( "delay", function() {
expect( 2 );
var element = $( "#autocomplete" ).autocomplete({
var element = $( "#autocomplete" ).autocomplete( {
source: data,
delay: 25
}),
} ),
menu = element.autocomplete( "widget" );
element.val( "ja" ).trigger( "keydown" );
ok( menu.is( ":hidden" ), "menu is closed immediately after search" );
setTimeout(function() {
setTimeout( function() {
ok( menu.is( ":visible" ), "menu is open after delay" );
start();
}, 50 );
});
} );
asyncTest( "disabled", function( assert ) {
expect( 5 );
var element = $( "#autocomplete" ).autocomplete({
var element = $( "#autocomplete" ).autocomplete( {
source: data,
delay: 0
}),
} ),
menu = element.autocomplete( "disable" ).autocomplete( "widget" );
element.val( "ja" ).trigger( "keydown" );
@ -133,17 +133,17 @@ asyncTest( "disabled", function( assert ) {
assert.hasClasses( menu, "ui-autocomplete-disabled" );
ok( !element.attr( "aria-disabled" ), "element doesn't get aria-disabled" );
setTimeout(function() {
setTimeout( function() {
ok( menu.is( ":hidden" ) );
start();
});
});
} );
} );
test( "minLength", function() {
expect( 2 );
var element = $( "#autocomplete" ).autocomplete({
var element = $( "#autocomplete" ).autocomplete( {
source: data
}),
} ),
menu = element.autocomplete( "widget" );
element.autocomplete( "search", "" );
ok( menu.is( ":hidden" ), "blank not enough for minLength: 1" );
@ -151,19 +151,19 @@ test( "minLength", function() {
element.autocomplete( "option", "minLength", 0 );
element.autocomplete( "search", "" );
ok( menu.is( ":visible" ), "blank enough for minLength: 0" );
});
} );
asyncTest( "minLength, exceed then drop below", function() {
expect( 4 );
var element = $( "#autocomplete" ).autocomplete({
var element = $( "#autocomplete" ).autocomplete( {
minLength: 2,
source: function( req, res ) {
equal( req.term, "12", "correct search term" );
setTimeout(function() {
res([ "item" ]);
});
setTimeout( function() {
res( [ "item" ] );
} );
}
}),
} ),
menu = element.autocomplete( "widget" );
ok( menu.is( ":hidden" ), "menu is hidden before first search" );
@ -172,55 +172,57 @@ asyncTest( "minLength, exceed then drop below", function() {
ok( menu.is( ":hidden" ), "menu is hidden before second search" );
element.autocomplete( "search", "1" );
setTimeout(function() {
setTimeout( function() {
ok( menu.is( ":hidden" ), "menu is hidden after searches" );
start();
});
});
} );
} );
test( "minLength, exceed then drop below then exceed", function() {
expect( 3 );
var _res = [],
element = $( "#autocomplete" ).autocomplete({
element = $( "#autocomplete" ).autocomplete( {
minLength: 2,
source: function( req, res ) {
_res.push( res );
}
}),
} ),
menu = element.autocomplete( "widget" );
// trigger a valid search
// Trigger a valid search
ok( menu.is( ":hidden" ), "menu is hidden before first search" );
element.autocomplete( "search", "12" );
// trigger a search below the minLength, to turn on cancelSearch flag
// Trigger a search below the minLength, to turn on cancelSearch flag
ok( menu.is( ":hidden" ), "menu is hidden before second search" );
element.autocomplete( "search", "1" );
// trigger a valid search
// Trigger a valid search
element.autocomplete( "search", "13" );
// react as if the first search was cancelled (default ajax behavior)
_res[ 0 ]([]);
// react to second search
_res[ 1 ]([ "13" ]);
// React as if the first search was cancelled (default ajax behavior)
_res[ 0 ]( [] );
// React to second search
_res[ 1 ]( [ "13" ] );
ok( menu.is( ":visible" ), "menu is visible after searches" );
});
} );
test( "source, local string array", function() {
expect( 1 );
var element = $( "#autocomplete" ).autocomplete({
var element = $( "#autocomplete" ).autocomplete( {
source: data
}),
} ),
menu = element.autocomplete( "widget" );
element.val( "ja" ).autocomplete( "search" );
equal( menu.find( ".ui-menu-item" ).text(), "javajavascript" );
});
} );
function sourceTest( source, async ) {
var element = $( "#autocomplete" ).autocomplete({
var element = $( "#autocomplete" ).autocomplete( {
source: source
}),
} ),
menu = element.autocomplete( "widget" );
function result() {
var items = menu.find( ".ui-menu-item" );
@ -228,15 +230,15 @@ function sourceTest( source, async ) {
deepEqual( items.eq( 0 ).data( "ui-autocomplete-item" ), {
label: "java",
value: "java"
});
} );
deepEqual( items.eq( 1 ).data( "ui-autocomplete-item" ), {
label: "javascript",
value: "javascript"
});
} );
deepEqual( items.eq( 2 ).data( "ui-autocomplete-item" ), {
label: "clojure",
value: "clojure"
});
} );
element.autocomplete( "destroy" );
if ( async ) {
start();
@ -254,64 +256,64 @@ function sourceTest( source, async ) {
test( "source, local object array, only labels", function() {
expect( 4 );
sourceTest([
sourceTest( [
{ label: "java", value: null },
{ label: "php", value: null },
{ label: "coldfusion", value: "" },
{ label: "javascript", value: "" },
{ label: "clojure" }
]);
});
] );
} );
test( "source, local object array, only values", function() {
expect( 4 );
sourceTest([
sourceTest( [
{ value: "java", label: null },
{ value: "php", label: null },
{ value: "coldfusion", label: "" },
{ value: "javascript", label: "" },
{ value: "clojure" }
]);
});
] );
} );
test( "source, url string with remote json string array", function() {
expect( 4 );
sourceTest( "remote_string_array.txt", true );
});
} );
test( "source, url string with remote json object array, only value properties", function() {
expect( 4 );
sourceTest( "remote_object_array_values.txt", true );
});
} );
test( "source, url string with remote json object array, only label properties", function() {
expect( 4 );
sourceTest( "remote_object_array_labels.txt", true );
});
} );
test( "source, custom", function() {
expect( 5 );
sourceTest(function( request, response ) {
sourceTest( function( request, response ) {
equal( request.term, "j" );
response([
response( [
"java",
{ label: "javascript", value: null },
{ value: "clojure", label: null }
]);
});
});
] );
} );
} );
test( "source, update after init", function() {
expect( 2 );
var element = $( "#autocomplete" ).autocomplete({
var element = $( "#autocomplete" ).autocomplete( {
source: [ "java", "javascript", "haskell" ]
}),
} ),
menu = element.autocomplete( "widget" );
element.val( "ja" ).autocomplete( "search" );
equal( menu.find( ".ui-menu-item" ).text(), "javajavascript" );
element.autocomplete( "option", "source", [ "php", "asp" ] );
element.val( "ph" ).autocomplete( "search" );
equal( menu.find( ".ui-menu-item" ).text(), "php" );
});
} );
} );

View File

@ -51,7 +51,7 @@ $.widget( "ui.autocomplete", {
},
source: null,
// callbacks
// Callbacks
change: null,
close: null,
focus: null,
@ -165,7 +165,7 @@ $.widget( "ui.autocomplete", {
return;
}
// replicate some key handlers to allow them to repeat in Firefox and Opera
// Replicate some key handlers to allow them to repeat in Firefox and Opera
var keyCode = $.ui.keyCode;
switch ( event.keyCode ) {
case keyCode.PAGE_UP:
@ -239,7 +239,7 @@ $.widget( "ui.autocomplete", {
}
} );
// clicking on the scrollbar causes focus to shift to the body
// Clicking on the scrollbar causes focus to shift to the body
// but we can't detect a mouseup or a click immediately afterward
// so we have to track the next mousedown and close the menu if
// the user clicks somewhere outside of the autocomplete
@ -293,7 +293,7 @@ $.widget( "ui.autocomplete", {
var item = ui.item.data( "ui-autocomplete-item" ),
previous = this.previous;
// only trigger when focus was lost (click on menu)
// Only trigger when focus was lost (click on menu)
if ( this.element[ 0 ] !== $.ui.safeActiveElement( this.document[ 0 ] ) ) {
this.element.trigger( "focus" );
this.previous = previous;
@ -327,7 +327,7 @@ $.widget( "ui.autocomplete", {
this._addClass( this.liveRegion, null, "ui-helper-hidden-accessible" );
// turning off autocomplete prevents the browser from remembering the
// Turning off autocomplete prevents the browser from remembering the
// value when navigating through history, so we re-enable autocomplete
// if the page is unloaded before the widget is destroyed. #7790
this._on( this.window, {
@ -427,7 +427,7 @@ $.widget( "ui.autocomplete", {
search: function( value, event ) {
value = value != null ? value : this._value();
// always save the actual value, not the one passed as an argument
// Always save the actual value, not the one passed as an argument
this.term = this._value();
if ( value.length < this.options.minLength ) {
@ -523,7 +523,7 @@ $.widget( "ui.autocomplete", {
this.isNewMenu = true;
this.menu.refresh();
// size and position menu
// Size and position menu
ul.show();
this._resizeMenu();
ul.position( $.extend( {
@ -592,7 +592,7 @@ $.widget( "ui.autocomplete", {
if ( !this.isMultiLine || this.menu.element.is( ":visible" ) ) {
this._move( keyEvent, event );
// prevents moving cursor to beginning/end of the text field in some browsers
// Prevents moving cursor to beginning/end of the text field in some browsers
event.preventDefault();
}
}
@ -610,7 +610,7 @@ $.extend( $.ui.autocomplete, {
}
} );
// live region extension, adding a `messages` option
// Live region extension, adding a `messages` option
// NOTE: This is an experimental API. We are still investigating
// a full solution for string manipulation and internationalization.
$.widget( "ui.autocomplete", $.ui.autocomplete, {