2

In rails 4.0, I am trying to implement tags input field using jquery tagit() plugin. In this plugin, user should select the input tags from autocompletion list not by custom entry. Here how can I avoid the custom entry? And also here, I mentioned minLength as 2 but the autocompletion list is showing when I type the first letter itself.

For code reference I used https://github.com/aehlke/tag-it

Code is,

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
           }
         }));
       }
     });
   }
 });
});

If i mentioned allowNewTags: false also it is not working.

Shruthi R
  • 1,863
  • 4
  • 39
  • 77

1 Answers1

0

From inspecting the tagit source code, it doesn't look like that option is available.

I'd do what they say here: 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;
        }
    }
});
Community
  • 1
  • 1
Martín Coll
  • 3,368
  • 3
  • 37
  • 52