Skip to content

Commit

Permalink
add readOnly option
Browse files Browse the repository at this point in the history
  • Loading branch information
ptr07 authored and aehlke committed Nov 23, 2012
1 parent 28e6161 commit 5204335
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 24 deletions.
6 changes: 6 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ For example, the user can enter `John Smith` instead of `"John Smith"`.

Defaults to *false*.

### readOnly (boolean)

When enabled, tag-it just render tags. It disables the ability to edit tags.

Defaults to *false*.

### singleField (boolean)

When enabled, will use a single hidden field for the form, rather than one per tag.
Expand Down
12 changes: 10 additions & 2 deletions css/jquery.tagit.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ ul.tagit li {
float: left;
margin: 2px 5px 2px 0;
}
ul.tagit li.tagit-choice {
padding: .2em 18px .2em .5em;
ul.tagit li.tagit-choice {
position: relative;
line-height: inherit;
}

ul.tagit li.tagit-choice-read-only {
padding: .2em .5em .2em .5em;
}

ul.tagit li.tagit-choice-editable {
padding: .2em 18px .2em .5em;
}

ul.tagit li.tagit-new {
padding: .25em 4px .25em 0;
}
Expand Down
20 changes: 20 additions & 0 deletions examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@
}
});


//-------------------------------
// Tag-it methods
//-------------------------------
$('#readOnlyTags').tagit({
readOnly: true
});

//-------------------------------
// Tag-it methods
//-------------------------------
Expand Down Expand Up @@ -207,6 +215,18 @@ <h3>Events</h3>
<div id="events_container"></div>

<hr>

<h3>Read-only</h3>
<form>
<p>Example of read only tags.</p>
<ul id="readOnlyTags">
<li>Tag1</li>
<li>Tag2</li>
</ul>
</form>

<hr>

<h3>Methods</h3>
<form>
<p>Demos the available widget methods. Click the links below the widget to try them.</p>
Expand Down
32 changes: 21 additions & 11 deletions js/tag-it.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
placeholderText : null,
allowDuplicates : false,

// When enabled, tag-it just render tags.
// It disables the ability to edit tags.
readOnly: false,

// When enabled, quotes are not neccesary
// for inputting multi-word tags.
allowSpaces: false,
Expand Down Expand Up @@ -109,6 +113,7 @@
}

this.tagInput = $('<input type="text" />').addClass('ui-widget-content');
if (this.options.readOnly) this.tagInput.attr('disabled', 'disabled');
if (this.options.tabIndex) {
this.tagInput.attr('tabindex', this.options.tabIndex);
}
Expand Down Expand Up @@ -346,17 +351,22 @@
.addClass(additionalClass)
.append(label);

// Button for removing the tag.
var removeTagIcon = $('<span></span>')
.addClass('ui-icon ui-icon-close');
var removeTag = $('<a><span class="text-icon">\xd7</span></a>') // \xd7 is an X
.addClass('tagit-close')
.append(removeTagIcon)
.click(function(e) {
// Removes a tag when the little 'x' is clicked.
that.removeTag(tag);
});
tag.append(removeTag);
if (this.options.readOnly){
tag.addClass('tagit-choice-read-only');
} else {
tag.addClass('tagit-choice-editable');
// Button for removing the tag.
var removeTagIcon = $('<span></span>')
.addClass('ui-icon ui-icon-close');
var removeTag = $('<a><span class="text-icon">\xd7</span></a>') // \xd7 is an X
.addClass('tagit-close')
.append(removeTagIcon)
.click(function(e) {
// Removes a tag when the little 'x' is clicked.
that.removeTag(tag);
});
tag.append(removeTag);
}

// Unless options.singleField is set, each tag has a hidden input field inline.
if (this.options.singleField) {
Expand Down
22 changes: 11 additions & 11 deletions js/tag-it.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5204335

Please sign in to comment.