Skip to content

Commit 81bea10

Browse files
committed
Add onDuplicate callback
Having an onDuplicate callback allows the developer to customize what happens on the gui and gives them the oppurtunity to perform any other specialized code.
1 parent 8319f64 commit 81bea10

File tree

2 files changed

+65
-7
lines changed

2 files changed

+65
-7
lines changed

index.html

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,48 @@ <h1>Bootstrap Tags Demo</h1>
107107
</style>
108108
</div>
109109
</div>
110+
<div class="row">
111+
<div class="span4"><h3>Tags in a Form</h3>
112+
<p>This is an example of including tags in a form and using a custom function when duplicate tags are added.</p>
113+
</div>
114+
<form >
115+
<div id="bs-tags-form"></div>
116+
<button type="submit" class="btn">Submit</button>
117+
<style type="text/css">
118+
button {
119+
margin-left: 30%;
120+
}
121+
#bs-tags-form .tag-badge {
122+
margin-right: 5px;
123+
margin-bottom: 5px;
124+
font-weight: 100;
125+
font-size: 14px;
126+
line-height: 20px;
127+
}
128+
#bs-tags-form .tag-icon {
129+
margin-left: 5px;
130+
margin-right: -3px;
131+
}
132+
#bs-tags-form .tag-badge a.tag-link {
133+
color: #ffffff;
134+
text-decoration: underline;
135+
}
136+
#bs-tags-form .tag-input {
137+
border: 0 solid;
138+
margin: 0;
139+
padding: 0;
140+
font-weight: 100;
141+
border: 0 solid;
142+
background-color: transparent;
143+
height: 18px;
144+
margin-top: -5px;
145+
color: #ffffff;
146+
outline: none;
147+
}
148+
</style>
149+
</form>
150+
</div>
151+
</div>
110152
<br><br>
111153
<div id="disqus_thread"></div>
112154
<script type="text/javascript">
@@ -149,6 +191,15 @@ <h1>Bootstrap Tags Demo</h1>
149191
},
150192
values_url: 'urls/default_users.json'
151193
});
194+
$('#bs-tags-form').tags({
195+
suggestions: ["Banana", "Durian", "Cocos"],
196+
suggestion_url: "urls/suggestions.json.php",
197+
values_url: 'urls/defaults.json',
198+
onDuplicate: function(original, duplicate){
199+
$(original).hide().fadeIn();
200+
return false;
201+
}
202+
});
152203
</script>
153204
</body>
154205
</html>

js/bootstrap-tags.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
},
5454
onLoadSuggestions: function(values) {
5555
return values;
56-
}
56+
},
57+
onDuplicate: null
5758
}
5859

5960

@@ -228,13 +229,19 @@
228229
});
229230

230231
if(unique) {
231-
var color = $(pills_list.children()[0]).css('background-color');
232-
unique.stop().animate({"backgroundColor": $self.options.double_hilight}, 100, 'swing', function() {
233-
unique.stop().animate({"backgroundColor": color}, 100, 'swing', function(){
234-
unique.css('background-color', '');
232+
if(!$self.options.onDuplicate){
233+
var color = $(pills_list.children()[0]).css('background-color');
234+
unique.stop().animate({"backgroundColor": $self.options.double_hilight}, 100, 'swing', function() {
235+
unique.stop().animate({"backgroundColor": color}, 100, 'swing', function(){
236+
unique.css('background-color', '');
237+
});
235238
});
236-
});
237-
return false;
239+
return false;
240+
} else {
241+
if($self.options.onDuplicate(unique, value) != true) {
242+
return false;
243+
}
244+
}
238245
}
239246

240247
if(value.url) {

0 commit comments

Comments
 (0)