首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >devbridge自动完成howto为空搜索字段

devbridge自动完成howto为空搜索字段
EN

Stack Overflow用户
提问于 2018-02-25 19:48:12
回答 1查看 341关注 0票数 0

文本字段用于向帖子添加标签。如果没有合适的任务,应该可以添加另一个标记。我没有发现通过"noSuggestionNotice“这样做的可能性-所以我也通过AJAX发送数据”添加‘来自搜索域的输入’作为新的标签“在我的AJAX搜索方法中,但当我选择这个条目时,文本字段仍然是”添加‘来自搜索域的输入’作为新的标签“--这看起来很奇怪,当你点击这个字段时,新的建议是”添加‘添加来自搜索域的输入’作为新的标签‘“,有可能清空搜索字段吗?下面是js-code:

代码语言:javascript
运行
复制
$('#appbundle_blog_post_additionalOtherTag').autocomplete({
    serviceUrl: '{{ path('post_othertag_search') }}',
    paramName: 'otherTag',
    triggerSelectOnValidInput: false,
    minChars: 3,
    showNoSuggestionNotice: true,
    noSuggestionNotice: 'Keine Tags vorhanden!',
    onSelect: function (suggestion) {
        {# load suggestions #}
        $.post('{{ path('post_othertag_add', {'id':post.id}) }}', { name: suggestion.value, otherId: suggestion.data })
            .done(function (data) {
                $('#otherTags').html(data);
            })
            .fail(function (data) {
                console.log('Fehler:');
                console.log(data);
            });
    }
}).onclick($('#appbundle_blog_post_additionalOtherTag').empty());
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-27 00:22:47

我自己发现的。这似乎是基本的jquery知识。

代码语言:javascript
运行
复制
$('#appbundle_blog_post_additionalOtherTag').val("");

所以完整的脚本是:

代码语言:javascript
运行
复制
$('#appbundle_blog_post_additionalOtherTag').autocomplete({
    serviceUrl: '{{ path('post_othertag_search') }}',
    paramName: 'otherTag',
    triggerSelectOnValidInput: false,
    minChars: 3,
    showNoSuggestionNotice: true,
    noSuggestionNotice: 'Keine Tags vorhanden!',
    onSelect: function (suggestion) {
        {# load suggestions #}
        $.post('{{ path('post_othertag_add', {'id':post.id}) }}', { name: suggestion.value, otherId: suggestion.data })
            .done(function (data) {
                $('#otherTags').html(data);
            })
            .fail(function (data) {
                console.log('Fehler:');
                console.log(data);
            });
        $('#appbundle_blog_post_additionalOtherTag').val("");
    }
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48973057

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档