mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Autocomplete: Fixed setting of valueMethod for textareas. Fixes #7674 - Autocomplete doesn't work with textareas.
This commit is contained in:
parent
87f78973b9
commit
c5ba0535cf
@ -39,6 +39,7 @@
|
|||||||
<div id="ac-wrap1" class="ac-wrap"></div>
|
<div id="ac-wrap1" class="ac-wrap"></div>
|
||||||
<div id="ac-wrap2" class="ac-wrap"><input id="autocomplete" class="foo"></div>
|
<div id="ac-wrap2" class="ac-wrap"><input id="autocomplete" class="foo"></div>
|
||||||
<div id="autocomplete-contenteditable" contenteditable="" tabindex=0></div>
|
<div id="autocomplete-contenteditable" contenteditable="" tabindex=0></div>
|
||||||
|
<textarea id="autocomplete-textarea"></textarea>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
@ -4,9 +4,26 @@ module( "autocomplete: events" );
|
|||||||
|
|
||||||
var data = [ "Clojure", "COBOL", "ColdFusion", "Java", "JavaScript", "Scala", "Scheme" ];
|
var data = [ "Clojure", "COBOL", "ColdFusion", "Java", "JavaScript", "Scala", "Scheme" ];
|
||||||
|
|
||||||
asyncTest( "all events", function() {
|
$.each([
|
||||||
|
{
|
||||||
|
type: "input",
|
||||||
|
selector: "#autocomplete",
|
||||||
|
valueMethod: "val"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "textarea",
|
||||||
|
selector: "#autocomplete-textarea",
|
||||||
|
valueMethod: "val"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "contenteditable",
|
||||||
|
selector: "#autocomplete-contenteditable",
|
||||||
|
valueMethod: "text"
|
||||||
|
}
|
||||||
|
], function( i, settings ) {
|
||||||
|
asyncTest( "all events - " + settings.type, function() {
|
||||||
expect( 13 );
|
expect( 13 );
|
||||||
var element = $( "#autocomplete" )
|
var element = $( settings.selector )
|
||||||
.autocomplete({
|
.autocomplete({
|
||||||
autoFocus: false,
|
autoFocus: false,
|
||||||
delay: 0,
|
delay: 0,
|
||||||
@ -46,7 +63,7 @@ asyncTest( "all events", function() {
|
|||||||
}),
|
}),
|
||||||
menu = element.autocomplete( "widget" );
|
menu = element.autocomplete( "widget" );
|
||||||
|
|
||||||
element.focus().val( "j" ).keydown();
|
element.focus()[ settings.valueMethod ]( "j" ).keydown();
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
ok( menu.is( ":visible" ), "menu is visible after delay" );
|
ok( menu.is( ":visible" ), "menu is visible after delay" );
|
||||||
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
||||||
@ -56,58 +73,6 @@ asyncTest( "all events", function() {
|
|||||||
element[0].blur();
|
element[0].blur();
|
||||||
}, 50 );
|
}, 50 );
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest( "all events - contenteditable", function() {
|
|
||||||
expect( 13 );
|
|
||||||
var element = $( "#autocomplete-contenteditable" )
|
|
||||||
.autocomplete({
|
|
||||||
autoFocus: false,
|
|
||||||
delay: 0,
|
|
||||||
source: data,
|
|
||||||
search: function( event ) {
|
|
||||||
equal( event.originalEvent.type, "keydown", "search originalEvent" );
|
|
||||||
},
|
|
||||||
response: function( event, ui ) {
|
|
||||||
deepEqual( ui.content, [
|
|
||||||
{ label: "Clojure", value: "Clojure" },
|
|
||||||
{ label: "Java", value: "Java" },
|
|
||||||
{ label: "JavaScript", value: "JavaScript" }
|
|
||||||
], "response ui.content" );
|
|
||||||
ui.content.splice( 0, 1 );
|
|
||||||
},
|
|
||||||
open: function( event ) {
|
|
||||||
ok( menu.is( ":visible" ), "menu open on open" );
|
|
||||||
},
|
|
||||||
focus: function( event, ui ) {
|
|
||||||
equal( event.originalEvent.type, "menufocus", "focus originalEvent" );
|
|
||||||
deepEqual( ui.item, { label: "Java", value: "Java" }, "focus ui.item" );
|
|
||||||
},
|
|
||||||
close: function( event ) {
|
|
||||||
equal( event.originalEvent.type, "menuselect", "close originalEvent" );
|
|
||||||
ok( menu.is( ":hidden" ), "menu closed on close" );
|
|
||||||
},
|
|
||||||
select: function( event, ui ) {
|
|
||||||
equal( event.originalEvent.type, "menuselect", "select originalEvent" );
|
|
||||||
deepEqual( ui.item, { label: "Java", value: "Java" }, "select ui.item" );
|
|
||||||
},
|
|
||||||
change: function( event, ui ) {
|
|
||||||
equal( event.originalEvent.type, "blur", "change originalEvent" );
|
|
||||||
deepEqual( ui.item, { label: "Java", value: "Java" }, "chnage ui.item" );
|
|
||||||
ok( menu.is( ":hidden" ), "menu closed on change" );
|
|
||||||
start();
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
menu = element.autocomplete( "widget" );
|
|
||||||
|
|
||||||
element.focus().text( "j" ).keydown();
|
|
||||||
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 } );
|
|
||||||
// TODO: blurring through jQuery causes a bug in IE 6 which causes the
|
|
||||||
// autocompletechange event to occur twice
|
|
||||||
element[0].blur();
|
|
||||||
}, 50 );
|
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest( "change without selection", function() {
|
asyncTest( "change without selection", function() {
|
||||||
|
2
ui/jquery.ui.autocomplete.js
vendored
2
ui/jquery.ui.autocomplete.js
vendored
@ -51,7 +51,7 @@ $.widget( "ui.autocomplete", {
|
|||||||
suppressKeyPress,
|
suppressKeyPress,
|
||||||
suppressInput;
|
suppressInput;
|
||||||
|
|
||||||
this.valueMethod = this.element[ this.element.is( "input" ) ? "val" : "text" ];
|
this.valueMethod = this.element[ this.element.is( "input,textarea" ) ? "val" : "text" ];
|
||||||
|
|
||||||
this.element
|
this.element
|
||||||
.addClass( "ui-autocomplete-input" )
|
.addClass( "ui-autocomplete-input" )
|
||||||
|
Loading…
Reference in New Issue
Block a user