在Rails4.0中,我尝试使用jquery tagit()插件实现标签输入字段。在这个插件中,用户应该从自动完成列表中选择输入标签,而不是通过自定义条目。在这里,我如何避免自定义条目?同样在这里,我提到minLength为2,但是当我输入第一个字母时,自动补全列表就会显示出来。
对于代码参考,我使用了https://github.com/aehlke/tag-it
代码是,
jQuery(document).ready(function() {
jQuery("#DIV_USERNAME").tagit({
minLength: 2,
tagLimit: 3,
allowNewTags: false,
placeholderText: "You can enter only 3 tags",
tagSource: function( request, response ) {
$.ajax({
url: "autocomplete/names",
data: { term:request.term },
dataType: "json",
success: function( data ) {
response( $.map( data, function( item ) {
return {
label: item.value
}
}));
}
});
}
});
});如果我提到allowNewTags: false,它也不起作用。
发布于 2015-07-08 03:22:21
从对tagit源代码的检查来看,该选项似乎不可用。
我会照他们说的做:https://stackoverflow.com/a/30495652。
var tags_list = ['tag1', 'tag2', 'tag3'];
$("input[name='subject-tags']").tagit({
availableTags : tags_list,
beforeTagAdded : function(event, ui) {
if(tags_list.indexOf(ui.tagLabel) == -1){
return false;
}
}
});https://stackoverflow.com/questions/19378069
复制相似问题