aboutsummaryrefslogtreecommitdiffstats
path: root/demos/autocomplete/combobox.html
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2010-07-20 14:35:54 -0400
committerScott González <scott.gonzalez@gmail.com>2010-07-20 14:35:54 -0400
commit5d1e29764024128e9cc71a19589cfe11e6241242 (patch)
treec9e3cca38e0b4c7fc601c65228b1eb9023c635b8 /demos/autocomplete/combobox.html
parentba091650ffdd2e359624413a90079e1369048142 (diff)
downloadjquery-ui-5d1e29764024128e9cc71a19589cfe11e6241242.tar.gz
jquery-ui-5d1e29764024128e9cc71a19589cfe11e6241242.zip
Autocomplete (combobox demo): Detect valid entries when typed, but not selected from menu. Fixes #5605 - Autocomplete combobox demo does not accept valid values.
Diffstat (limited to 'demos/autocomplete/combobox.html')
-rw-r--r--demos/autocomplete/combobox.html20
1 files changed, 15 insertions, 5 deletions
diff --git a/demos/autocomplete/combobox.html b/demos/autocomplete/combobox.html
index 37b74e155..c76cfa130 100644
--- a/demos/autocomplete/combobox.html
+++ b/demos/autocomplete/combobox.html
@@ -29,7 +29,7 @@
delay: 0,
minLength: 0,
source: function( request, response ) {
- var matcher = new RegExp( request.term, "i" );
+ var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
response( select.children( "option" ).map(function() {
var text = $( this ).text();
if ( this.value && ( !request.term || matcher.test(text) ) )
@@ -54,10 +54,20 @@
},
change: function( event, ui ) {
if ( !ui.item ) {
- // remove invalid value, as it didn't match anything
- $( this ).val( "" );
- select.val( "" );
- return false;
+ var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ),
+ valid = false;
+ select.children( "option" ).each(function() {
+ if ( this.value.match( matcher ) ) {
+ this.selected = valid = true;
+ return false;
+ }
+ });
+ if ( !valid ) {
+ // remove invalid value, as it didn't match anything
+ $( this ).val( "" );
+ select.val( "" );
+ return false;
+ }
}
}
})