jQuery用户界面自动完成 - 有害触发因特殊字符 [英] Jquery UI autocomplete - Unwanted triggering due to special characters
问题描述
我有几个自动完成的在我的应用程序。他们中有些人得到从数据库加载时填充。如果输入的值包含类似于æøå特殊字符,自动完成触发即使用户没有受到HTML输入附近的任何地方我的搜索。这仅适用于Internet Explorer 11(和可能更低)。在FF和铬它的作品如你所愿。
I have a few autocomplete's in my application. Some of them get populated from a database when loading. If the input value contains special characters like æøå, autocomplete triggers a search even if I the user haven't been anywhere near the html input. This only applies to Internet Explorer 11 (and possibly lower). In FF and Chrome it works as you would expect.
考虑下面输入:
<input type='text' class'ac' value='chars æøå' />
如果将自动完成该输入,其中可能的一个搜索结果是一样的默认值('字符æøå'),搜索会触发初始化。
If applying an autocomplete to this input where one of the possible search results is the same as the default value ('chars æøå'), the search will trigger on initialisation.
在这里的jsfiddle(使用IE浏览器,看看它触发负载): http://jsfiddle.net/BY9gU/一>
JSfiddle here (use IE to see it trigger on load): http://jsfiddle.net/BY9gU/
我很想只是忽略IE,但不幸的是我的一些客户仍然使用它...
I would LOVE to just disregard IE, but unfortunately some of my customers still use it...
的解决方法,任何想法?
Any ideas for a workaround?
推荐答案
由于@cverb状态,这是一个IE浏览器的问题,不能在jQuery UI的指责。但是,我做了一个解决办法,这似乎做工精细,至少在我的项目:
As @cverb states in his answer, this is an IE problem and can't be blamed on jQuery UI. However, I've made a workaround which seems to work fine, at least in my project:
在找到jQuery UI的源本code:
Locate this code in jquery ui source:
search: function( value, event ) {
value = value != null ? value : this._value();
// always save the actual value, not the one passed as an argument
this.term = this._value();
if ( value.length < this.options.minLength ) {
return this.close( event );
}
改成这样(加if块):
Change it to this (add the if-block):
search: function( value, event ) {
value = value != null ? value : this._value();
// The following if-block is inserted by me as a workaround.
// Add all characters which may cause you trouble in the
// regex pattern.
if ( this._value().match(/[æøåÆØÅ]/) && this.term === undefined ) {
return;
}
// always save the actual value, not the one passed as an argument
this.term = this._value();
if ( value.length < this.options.minLength ) {
return this.close( event );
}
瞧!有用。我不能保证,我没有打破一些其他的功能,但我99.9%肯定,我没有:)
Voila! It works. I can't guarantee that I haven't broken some other functionality, but I'm 99,9% sure that I haven't :)
这篇关于jQuery用户界面自动完成 - 有害触发因特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!