I use tag-it plugin from https://github.com/aehlke/tag-it/downloads. How to disable adding new tags?
$(document).ready(function () {
$("#Tags").tagit({
singleField: true,
singleFieldNode: $('#mySingleField'),
// onlyAvailableTags : true,
allowNewTags: false,
tagSource: [@Html.Raw(ViewBag.AvailableTags)]
});
});
I tried to use onlyAvailableTags : true and allowNewTags: false options, but there’s no effect.
Since you say “but there’s no effect”, I would guess that
@Html.Raw(ViewBag.AvailableTags)produces an output that that breaks the javascript syntax. The tags need to be in quotes, otherwise they are treated as variables.Incorrrect output:
Server-side, I assume you have some kind of
IEnumerable<string>:Then, in your
.cshtml:This would produce the correct output:
That would be what I’d try first.