John Hunt John Hunt - 5 years ago 231
Javascript Question

jQuery Autocomplete mustmatch doesn't have any effect

I'm using jQuery 1.4.4 and jQuery UI 1.8.9. I have an autocomplete field that works really well, however I'd like to contrain the input to only what the autocomplete backend comes up with.

The documetation states:


mustMatch Boolean Default: false

If set to true, the autocompleter will
only allow results that are presented
by the backend. Note that illegal
values result in an empty input box.


However, when I set mustMatch to true, it doesn't make any difference - I can still type in anything I like and nothing happens.

I'm fairly sure this is something I'm doing and not a bug as I haven't seen anything on google that points to that.

Here's a code snippet:

$( ".client" ).autocomplete({
minLength: 2,
mustMatch: true,
source: function( request, response ) {
var term = request.term;
if ( term in client_cache ) {
response( client_cache[ term ] );
return;
}

client_lastXhr = $.getJSON( "amex/start.php?action=autocomplete&field=client", request, function( data, status, xhr ) {
client_cache[ term ] = data;
if ( xhr === client_lastXhr ) {
response( data );
}
});
}
});


Can anyone see what I'm doing wrong? Thanks for your help!

Answer Source

You probably found this option on the documentation page for the deprecated plugin. jQueryUI's current documentation is located here.

It looks like they removed the mustMatch option, but according to this StackOverflow question, you can implement it yourself.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download