mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Autocomplete: Normalize falsy values, not just missing values
Fixes #9762
This commit is contained in:
parent
2ef1b16e4d
commit
113e9d0c2c
@ -220,7 +220,20 @@ function sourceTest( source, async ) {
|
||||
}),
|
||||
menu = element.autocomplete( "widget" );
|
||||
function result() {
|
||||
equal( menu.find( ".ui-menu-item" ).text(), "javajavascript" );
|
||||
var items = menu.find( ".ui-menu-item" );
|
||||
equal( items.length, 3, "Should find three results." );
|
||||
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();
|
||||
@ -230,52 +243,58 @@ function sourceTest( source, async ) {
|
||||
stop();
|
||||
$( document ).one( "ajaxStop", result );
|
||||
}
|
||||
element.val( "ja" ).autocomplete( "search" );
|
||||
element.val( "j" ).autocomplete( "search" );
|
||||
if ( !async ) {
|
||||
result();
|
||||
}
|
||||
}
|
||||
|
||||
test( "source, local object array, only label property", function() {
|
||||
expect( 1 );
|
||||
test( "source, local object array, only labels", function() {
|
||||
expect( 4 );
|
||||
sourceTest([
|
||||
{ label: "java" },
|
||||
{ label: "php" },
|
||||
{ label: "coldfusion" },
|
||||
{ label: "javascript" }
|
||||
{ label: "java", value: null },
|
||||
{ label: "php", value: null },
|
||||
{ label: "coldfusion", value: "" },
|
||||
{ label: "javascript", value: "" },
|
||||
{ label: "clojure" }
|
||||
]);
|
||||
});
|
||||
|
||||
test( "source, local object array, only value property", function() {
|
||||
expect( 1 );
|
||||
test( "source, local object array, only values", function() {
|
||||
expect( 4 );
|
||||
sourceTest([
|
||||
{ value: "java" },
|
||||
{ value: "php" },
|
||||
{ value: "coldfusion" },
|
||||
{ value: "javascript" }
|
||||
{ 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( 1 );
|
||||
expect( 4 );
|
||||
sourceTest( "remote_string_array.txt", true );
|
||||
});
|
||||
|
||||
test( "source, url string with remote json object array, only value properties", function() {
|
||||
expect( 1 );
|
||||
expect( 4 );
|
||||
sourceTest( "remote_object_array_values.txt", true );
|
||||
});
|
||||
|
||||
test( "source, url string with remote json object array, only label properties", function() {
|
||||
expect( 1 );
|
||||
expect( 4 );
|
||||
sourceTest( "remote_object_array_labels.txt", true );
|
||||
});
|
||||
|
||||
test( "source, custom", function() {
|
||||
expect( 2 );
|
||||
expect( 5 );
|
||||
sourceTest(function( request, response ) {
|
||||
equal( request.term, "ja" );
|
||||
response( ["java", "javascript"] );
|
||||
equal( request.term, "j" );
|
||||
response([
|
||||
"java",
|
||||
{ label: "javascript", value: null },
|
||||
{ value: "clojure", label: null }
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1 +1,5 @@
|
||||
[{"label":"java"},{"label":"javascript"}]
|
||||
[
|
||||
{ "label": "java", "value": null },
|
||||
{ "label": "javascript", "value": "" },
|
||||
{ "label": "clojure" }
|
||||
]
|
||||
|
@ -1 +1,5 @@
|
||||
[{"value":"java"},{"value":"javascript"}]
|
||||
[
|
||||
{ "value": "java", "label": null },
|
||||
{ "value": "javascript", "label": "" },
|
||||
{ "value": "clojure" }
|
||||
]
|
||||
|
@ -1 +1 @@
|
||||
["java", "javascript"]
|
||||
[ "java", "javascript", "clojure" ]
|
||||
|
4
ui/jquery.ui.autocomplete.js
vendored
4
ui/jquery.ui.autocomplete.js
vendored
@ -478,10 +478,10 @@ $.widget( "ui.autocomplete", {
|
||||
value: item
|
||||
};
|
||||
}
|
||||
return $.extend({
|
||||
return $.extend( {}, item, {
|
||||
label: item.label || item.value,
|
||||
value: item.value || item.label
|
||||
}, item );
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user