On 6/10/09 1:17 PM, "Brad" <nrmlcrpt...@gmail.com> wrote: > > I have an Autocomplete on a form that uses local data. However, the > input allows users to enter values that are not in the local data > array. If the user enters and selects matching data the .result > callback function sets a corresponding key value that is submitted > with the form. The intent is to help enter known values, but others > are allowed. > > What I'm observing is that if a match is entered, the corresponding > key will be set. But if the user further edits the matched value the > autocomplete doesn't fire again. This creates a problem because the > key never changes. Is that expected autocomplete behavior? If so, is > there a workaround? > > Here's the code: > > $("#calibration_location_name").autocomplete( locations, { > minChars: 0, > width: 310, > selectFirst: false, > scroll: true, > matchContains: "word", > mustMatch: false, > autoFill: false, > formatItem: function(row, i, max) { > return row.name; > }, > formatMatch: function(row, i, max) { > return row.name; > }, > formatResult: function(row) { > return row.name; > } > }) > .result(LocationAutoCompleteCallback) > .blur( function(){ > if($(this).val() === '') { > $("#calibration_locationkey").val(0); > } > });
i'm not sure i understand your problem entirely but my guess is that the formatX methods aren't necessarily the right solution for your problem. if what you want is to submit the key associated with the string in the input if and only if one exists in your array then you could perhaps do the key lookup at form submit time quite independently of the autocompletion plugin.