文本字段用于向帖子添加标签。如果没有合适的任务,应该可以添加另一个标记。我没有发现通过"noSuggestionNotice“这样做的可能性-所以我也通过AJAX发送数据”添加‘来自搜索域的输入’作为新的标签“在我的AJAX搜索方法中,但当我选择这个条目时,文本字段仍然是”添加‘来自搜索域的输入’作为新的标签“--这看起来很奇怪,当你点击这个字段时,新的建议是”添加‘添加来自搜索域的输入’作为新的标签‘“,有可能清空搜索字段吗?下面是js-code:
$('#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());发布于 2018-02-27 00:22:47
我自己发现的。这似乎是基本的jquery知识。
$('#appbundle_blog_post_additionalOtherTag').val("");所以完整的脚本是:
$('#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("");
    }
});https://stackoverflow.com/questions/48973057
复制相似问题