开发者

Autocomplete combobox resets on loss of focus - IE only

开发者 https://www.devze.com 2023-01-26 04:56 出处:网络
I am using jquery.ui.autocomplete on multiple comboboxes on a page.In IE only, the combobox resets 开发者_如何学Goon loss of focus (onBlur).No amount of JS debugging can reveal the cause.Any suggestio

I am using jquery.ui.autocomplete on multiple comboboxes on a page. In IE only, the combobox resets 开发者_如何学Goon loss of focus (onBlur). No amount of JS debugging can reveal the cause. Any suggestions?


Ok, here's what I came up with. I used your code and replicated your bug.

The reason that IE is different then say... firefox, is this routine:

                                    change: function (event, ui) {
                                        if (!ui.item) {

In firefox, ui.item is not null, in IE it is. So in IE it has to get the actual values of '<option value="foo">foo</option>' the value attribute, and compare with whats in the text box.

Here's the problem:

value="foo" must match exactly what is in >foo<

<option value="5">Five</option> 

Will cause it to clear the field when you blur

<option value="Five">Five</option>

Will not

In firefox and chrome, they pass ui so they don't get this check, it just continues on and everything is cool. Check to make sure your values match exactly what the option text is.


superfro's analysis is correct, but you can use option elements where the value differs from the text if you modify this single line of code:

if (this.value.match(matcher)) {

to:

if ($(this).text().match(matcher)) {

This way, you're matching against TEXT inside of <option value="VALUE">TEXT</option> instead of VALUE.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号