我正在创建一个输入字段,其中包含标记和输入,使用tagify插件-节-mix-(参见:https://yaireo.github.io/tagify/#section-mix)。
问题是:
注意,只有当该值与任何白色项的值匹配时,才能创建标记。
我想通过点击enter来自己添加它们,就像链接中的其他示例一样。知道如何用标签来解决这个问题吗?
<textarea name='mix'>@cartman and @kyle do not know #homer who is #lisa</textarea>JAVASCRIPT
var input = document.querySelector('[name=mix]'),
// init Tagify script on the above inputs
tagify = new Tagify(input, {
mode : 'mix', // <-- Enable mixed-content
pattern : /@/, // <-- Tag words which start with # (can be a String instead of Regex)
whitelist : [
{
value: 'Homer'
}
],
dropdown : {
enabled : 1
}
})
var whitelist_2 = ['Homer', 'Marge', 'Bart', 'Lisa', 'Maggie', 'Mr. Burns', 'Ned', 'Milhouse', 'Moe'];
// A good place to pull server suggestion list accoring to the prefix/value
tagify.on('input', function(e){
var prefix = e.detail.prefix;
if( prefix == '#' )
tagify.settings.whitelist = whitelist_2;
if( e.detail.value.length > 1 )
tagify.dropdown.show.call(tagify, e.detail.value);
}发布于 2020-02-07 20:30:00
现在,Tagify支持在混合模式下创建新标记(从版本3.4.0开始)。
请参阅标签化示例页
更新2020年2月24日
目前只有没有空格的标签才能被添加,因为在混合模式中添加新标签的实现没有解决的复杂性。我很快就会解决这个问题。
https://stackoverflow.com/questions/54365459
复制相似问题