Skip to content

Commit

Permalink
I added support for the blur event so that the tags are properly crea…
Browse files Browse the repository at this point in the history
…ted when the input is blurred.
  • Loading branch information
fdeschenes committed Feb 13, 2013
1 parent beeba92 commit fb9d081
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions js/bootstrap-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,15 @@
that.element.parent().addClass('tags-hover')
})
.on('blur', function () {
that.process()
that.element.parent().removeClass('tags-hover')
that.element.siblings('.tag').removeClass('tag-important')
})
.on('keydown', function ( event ) {
if ( event.keyCode == 188 || event.keyCode == 13 || event.keyCode == 9 ) {
if ( $.trim($(this).val()) && ( !that.element.siblings('.typeahead').length || that.element.siblings('.typeahead').is(':hidden') ) ) {
var values = $.grep($.map($(this).val().split(','), $.trim), function ( value ) { return value.length > 0 })
if ( event.keyCode != 9 ) event.preventDefault()
$.each(values, function() {
that.add(this)
})
$(this).val('')
that.process()
} else if ( event.keyCode == 188 ) {
if ( !that.element.siblings('.typeahead').length || that.element.siblings('.typeahead').is(':hidden') ) {
event.preventDefault()
Expand Down Expand Up @@ -150,6 +147,14 @@
this.element.val(this.values.join(', '))
}
}
, process: function () {
var values = $.grep($.map(this.input.val().split(','), $.trim), function ( value ) { return value.length > 0 }),
that = this
$.each(values, function() {
that.add(this)
})
this.input.val('')
}
}

var old = $.fn.tag
Expand Down

0 comments on commit fb9d081

Please sign in to comment.