aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2014-01-22 10:40:19 -0500
committerScott González <scott.gonzalez@gmail.com>2014-01-22 10:40:19 -0500
commit113e9d0c2cc3f474da719721857c074c983c7157 (patch)
tree0dbae897accf436d7306d00188c23321a2375d0b
parent2ef1b16e4d3aa8766084e50f4a1d806c434e7e43 (diff)
downloadjquery-ui-113e9d0c2cc3f474da719721857c074c983c7157.tar.gz
jquery-ui-113e9d0c2cc3f474da719721857c074c983c7157.zip
Autocomplete: Normalize falsy values, not just missing values
Fixes #9762
-rw-r--r--tests/unit/autocomplete/autocomplete_options.js59
-rw-r--r--tests/unit/autocomplete/remote_object_array_labels.txt6
-rw-r--r--tests/unit/autocomplete/remote_object_array_values.txt6
-rw-r--r--tests/unit/autocomplete/remote_string_array.txt2
-rw-r--r--ui/jquery.ui.autocomplete.js4
5 files changed, 52 insertions, 25 deletions
diff --git a/tests/unit/autocomplete/autocomplete_options.js b/tests/unit/autocomplete/autocomplete_options.js
index fee37aee4..c2cb2149d 100644
--- a/tests/unit/autocomplete/autocomplete_options.js
+++ b/tests/unit/autocomplete/autocomplete_options.js
@@ -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 }
+ ]);
});
});
diff --git a/tests/unit/autocomplete/remote_object_array_labels.txt b/tests/unit/autocomplete/remote_object_array_labels.txt
index 502496c25..f6be4c86f 100644
--- a/tests/unit/autocomplete/remote_object_array_labels.txt
+++ b/tests/unit/autocomplete/remote_object_array_labels.txt
@@ -1 +1,5 @@
-[{"label":"java"},{"label":"javascript"}] \ No newline at end of file
+[
+ { "label": "java", "value": null },
+ { "label": "javascript", "value": "" },
+ { "label": "clojure" }
+]
diff --git a/tests/unit/autocomplete/remote_object_array_values.txt b/tests/unit/autocomplete/remote_object_array_values.txt
index 029cbb9df..d55252b98 100644
--- a/tests/unit/autocomplete/remote_object_array_values.txt
+++ b/tests/unit/autocomplete/remote_object_array_values.txt
@@ -1 +1,5 @@
-[{"value":"java"},{"value":"javascript"}] \ No newline at end of file
+[
+ { "value": "java", "label": null },
+ { "value": "javascript", "label": "" },
+ { "value": "clojure" }
+]
diff --git a/tests/unit/autocomplete/remote_string_array.txt b/tests/unit/autocomplete/remote_string_array.txt
index 3b24c8e4b..76134f302 100644
--- a/tests/unit/autocomplete/remote_string_array.txt
+++ b/tests/unit/autocomplete/remote_string_array.txt
@@ -1 +1 @@
-["java", "javascript"] \ No newline at end of file
+[ "java", "javascript", "clojure" ]
diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js
index ca2458ea6..e40e703b9 100644
--- a/ui/jquery.ui.autocomplete.js
+++ b/ui/jquery.ui.autocomplete.js
@@ -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 );
+ });
});
},