+
+
+ diff --git a/src/jquery.tagsinput.css b/src/jquery.tagsinput.css index c595e24..745ca7f 100644 --- a/src/jquery.tagsinput.css +++ b/src/jquery.tagsinput.css @@ -1,4 +1,5 @@ div.tagsinput { border:1px solid #CCC; background: #FFF; padding:5px; width:300px; height:100px; overflow-y: auto;} +div.tagsinput.inputdisabled span.tag a { cursor:default;} div.tagsinput span.tag { border: 1px solid #a5d24a; -moz-border-radius:2px; -webkit-border-radius:2px; display: block; float: left; padding: 5px; text-decoration:none; background: #cde69c; color: #638421; margin-right: 5px; margin-bottom:5px;font-family: helvetica; font-size:13px;} div.tagsinput span.tag a { font-weight: bold; color: #82ad2b; text-decoration:none; font-size: 11px; } div.tagsinput input { width:80px; margin:0px; font-family: helvetica; font-size: 13px; border:1px solid transparent; padding:5px; background: transparent; color: #000; outline:0px; margin-right:5px; margin-bottom:5px; } diff --git a/src/jquery.tagsinput.js b/src/jquery.tagsinput.js index b6c75e4..06c15b7 100644 --- a/src/jquery.tagsinput.js +++ b/src/jquery.tagsinput.js @@ -76,6 +76,7 @@ $.fn.addTag = function(value,options) { options = jQuery.extend({focus:false,callback:true},options); this.each(function() { + var disabled = $(this).attr('data-inputdisabled'); var id = $(this).attr('id'); var tagslist = $(this).val().split(delimiter[id]); @@ -88,24 +89,24 @@ if (options.unique) { var skipTag = $(this).tagExist(value); if(skipTag == true) { - //Marks fake input as not_valid to let styling it - $('#'+id+'_tag').addClass('not_valid'); - } + //Marks fake input as not_valid to let styling it + $('#'+id+'_tag').addClass('not_valid'); + } } else { var skipTag = false; } if (value !='' && skipTag != true) { - $('').addClass('tag').append( - $('').text(value).append(' '), - $('', { - href : '#', - title : 'Removing tag', - text : 'x' - }).click(function () { - return $('#' + id).removeTag(escape(value)); - }) - ).insertBefore('#' + id + '_addTag'); + $('').addClass('tag').append( + $('').text(value).append(' '), + $('', { + href : '#', + title : 'Removing tag', + text : 'x' + }).click(function () { + return $('#' + id).removeTag(escape(value)); + }) + ).insertBefore('#' + id + '_addTag'); tagslist.push(value); @@ -129,7 +130,6 @@ f.call(this, $(this), tagslist[i-1]); } } - }); return false; @@ -138,24 +138,27 @@ $.fn.removeTag = function(value) { value = unescape(value); this.each(function() { - var id = $(this).attr('id'); - - var old = $(this).val().split(delimiter[id]); - - $('#'+id+'_tagsinput .tag').remove(); - str = ''; - for (i=0; i< old.length; i++) { - if (old[i]!=value) { - str = str + delimiter[id] +old[i]; + var disabled = $(this).attr('data-inputdisabled'); + if (!disabled) { + var id = $(this).attr('id'); + + var old = $(this).val().split(delimiter[id]); + + $('#'+id+'_tagsinput .tag').remove(); + str = ''; + for (i=0; i< old.length; i++) { + if (old[i]!=value) { + str = str + delimiter[id] +old[i]; + } } - } - $.fn.tagsInput.importTags(this,str); + $.fn.tagsInput.importTags(this,str); - if (tags_callbacks[id] && tags_callbacks[id]['onRemoveTag']) { - var f = tags_callbacks[id]['onRemoveTag']; - f.call(this, value); - } + if (tags_callbacks[id] && tags_callbacks[id]['onRemoveTag']) { + var f = tags_callbacks[id]['onRemoveTag']; + f.call(this, value); + } + } }); return false; @@ -189,7 +192,8 @@ placeholderColor:'#666666', autosize: true, comfortZone: 20, - inputPadding: 6*2 + inputPadding: 6*2, + honorDisabled: false },options); var uniqueIdCounter = 0; @@ -207,9 +211,17 @@ $(this).hide(); } var id = $(this).attr('id'); + if (!id || delimiter[$(this).attr('id')]) { id = $(this).attr('id', 'tags' + new Date().getTime() + (uniqueIdCounter++)).attr('id'); } + + // check if input is disabled + var disabled = settings.honorDisabled && ($(this).attr('disabled') === 'disabled'); + + if (disabled) { + $(this).attr('data-inputdisabled', true); + } var data = jQuery.extend({ pid:id, @@ -228,9 +240,15 @@ tags_callbacks[id]['onChange'] = settings.onChange; } - var markup = '