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.
This is what I did for the latest version of tag-it :
Tried to make it cleaner by implementing
But
this.availableTags
doesn't return the array (return :undefined
). I'm a JS noob, so something must be wrong with the way I access the property.I found that by commenting out:
And:
It removes this functionality. Perhaps not the cleanest way of doing it, but it works.
Just comment out the
if(){ }
loops.