Side navigation
#3287 closed feature (invalid)
Opened August 25, 2008 07:20AM UTC
Closed October 12, 2009 11:36PM UTC
[autocomplete] Add a handler for non-matched events
Reported by: | wichert | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.3 |
Component: | plugin | Version: | 1.2.6 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
A pattern I am using a lot is that I have a list of record with an id and a title. Autocompletion happens on the title and when an entry is selected I use the result handler to store the associated id in a hidden input field, which gets processed by my backend. The html looks like this:
<input type="hidden" name="brand" value="" id="realBrandValue"/> <label for="brandCompleter" id="articleBrand">Merk <input type="Text" name="brandCompleter"/> </label>
and the javascript looks like this:
$("label#articleBrand input").each(function() { var brandid = $("input#realBrandValue")[0].value; if (brandid) { for (var i=0; i!=brands.length; i++) { if (brands[i].value==brandid) { $(this).attr("value", brands[i].title); break; } } } }).autocomplete(brands, { autoFill : true, mustMatch : false, formatMatch: function (row, i, total) { return row.title; }, formatResult: function (row) { return row.title; }, formatItem: function (row, i, total) { return row.title; }, }).result(function(event, row) { $("input#realBrandValue").attr("value", row.value); });
For situations where users must be able to use unknown values this does not work since the result handler is not called for un-matched data input. What I am missing for that situation is a handler that allows me to catch that situation so I can update my hidden input field.
Looking at the code I see two ways to accomplish this:
- also trigger the result handler if selected evaluatues to
false at the beginning of selectCurrent(). This may have
backwards compatibility problems.
- add a new handler for this case and trigger that from
selectCurrent at the point where it current does a return false.
Attachments (0)
Change History (2)
Changed August 25, 2008 07:35AM UTC by comment:1
Changed October 12, 2009 11:36PM UTC by comment:2
resolution: | → invalid |
---|---|
status: | new → closed |
This is not a jQuery core bug. Please report plugin bugs to the plugin's author, or ask on the jQuery forums. jQuery UI bugs should be reported on the UI bug tracker, http://dev.jqueryui.com .
I noticed that the change handler for the input element is always fired before autocomplete fires the result handler, so as a workaround I always do the non-matching code on change and override that in the result handler later. Not very efficient, but it gets the job down.