Search code examples
jquery-uitag-it

Jquery UI tag-it widget - what's the best way to disable entries?


For the Jquery UI tag-it widget, I'd like to disable text input into the class="ui-widget-content ui-autocomplete-input" textbox which contains all the tags.

My purpose is to just allow certain people the ability to delete inappropriate tags, but not allow anybody to add tags (which are auto-generated).

Is the best thing for me to edit the tag-it .js file and add a disable="disable" for that field? If I do that, won't that prevent the contents of that field from being submitted? Or does that matter as long as the associated hidden field is submitted?

Or is there a better way of doing this (an overriding style?) without modifying the tag-it file itself?

Thanks,

doug


Solution

  • In tag-it.js I replaced this line:

    this._tagInput = $('<input type="text"').addClass('ui-widget-content');
    

    with this:

    this._tagInput = $('<input type="text" readonly="readonly"/>').addClass('ui-widget-content');
    

    adding the readonly="readonly" attribute. That had the desired effect of preventing input but still allowing users to delete inappropriate auto-generated tags.