YUI 自动完成:粘贴后搜索?

发布于 2024-08-02 00:11:37 字数 240 浏览 3 评论 0原文

我使用 YUI 中的自动完成小部件来实现实时搜索,如示例中所示。 但是,在输入搜索文本时它可以正常工作,但在将文本粘贴到字段中时则无法工作。 哪种方法是在粘贴时启动自动完成功能的正确方法? 在文档中没有找到任何相关内容...

编辑:粘贴不是 Ctrl-V,它通常是上下文菜单中的“粘贴”。 YUI 确实会对按键做出反应,但如果通过鼠标粘贴任何内容,则不会做出反应。

I'm using an auto-complete widget from YUI to implement live search as in the examples. However, it works fine when search text is typed in, but fails to work when the text is pasted into the field. Which would be the proper way to initiate an autocompletion on paste? Haven't found anything for that in the documentation...

EDIT: Pasting is not Ctrl-V, it's usually "Paste" from the context-menu. YUI does react to a keypress, but doesn't if anything is pasted by the mouse.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

樱花落人离去 2024-08-09 00:11:37

我们扩展了 YUI 的自动完成小部件,并以这种方式处理上下文菜单中的粘贴:

YAHOO.util.Event.on(input, 'paste', function(e, autocomplete) {
    // We're interested in the value of the input field after text is pasted into
    // it instead of the pasted text because the autocomplete proposals are based 
    // upon the field's whole value. The paste event happens before the input 
    // field has been updated so we need to wait until after this event has been 
    // handled to check the value of the input field.
    window.setTimeout(function() {
        if (autocomplete._sInitInputValue !== autocomplete.getInputEl().value) {
            autocomplete.sendQuery(autocomplete.getInputEl().value);
        }
    }, 1);
}, this);

其中 this 是自动完成小部件。

We have extended YUI's autocomplete widget and handle paste from the context menu in this way:

YAHOO.util.Event.on(input, 'paste', function(e, autocomplete) {
    // We're interested in the value of the input field after text is pasted into
    // it instead of the pasted text because the autocomplete proposals are based 
    // upon the field's whole value. The paste event happens before the input 
    // field has been updated so we need to wait until after this event has been 
    // handled to check the value of the input field.
    window.setTimeout(function() {
        if (autocomplete._sInitInputValue !== autocomplete.getInputEl().value) {
            autocomplete.sendQuery(autocomplete.getInputEl().value);
        }
    }, 1);
}, this);

Where this is the autocomplete widget.

ぺ禁宫浮华殁 2024-08-09 00:11:37

也许在按键事件中,您可以检测他们是否在按住 ctrl 的同时按下了 v。 如果有,则执行 sendQuery('query=' + textInput.value);

Perhaps on key event, you could detect if they pressed v while holding ctrl. If they have, then do a sendQuery('query=' + textInput.value);

ま昔日黯然 2024-08-09 00:11:37

编辑

这是一个兼容性表,显示哪些浏览器允许您订阅粘贴事件。

http://www.quirksmode.org/dom/events/cutcopypaste.html

这是他的测试页面,您可以在其中查看如何订阅事件。

http://www.quirksmode.org/dom/events/tests/cutcopypaste。 我想

你可以使用 YUI & 来订阅它。 然后让你的回调是这样的:

function() { 
    autoCompleteObject.sendQuery(autoCompleteElement.value);
}

注意浏览器不兼容,看起来有些事件的实现很奇怪。

Edit

Here's a compatibility table showing which browsers let you subscribe to the paste events.

http://www.quirksmode.org/dom/events/cutcopypaste.html

Here's his testing page where you can see how to subscribe to the events.

http://www.quirksmode.org/dom/events/tests/cutcopypaste.html

I imagine you could subscribe to that using YUI & then just have your callback be this:

function() { 
    autoCompleteObject.sendQuery(autoCompleteElement.value);
}

Watch out for browser incompatibilities, looks like some have a weird implementation of the events.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文