creating a tag using jquery bootstrap-tagsinput wi

2019-08-05 20:22发布

问题:

im using jquery bootstrap-tagsinput and currently the only method for creating a tag is by hitting the enter key after typing it in. What I am looking for is a more easy user method of creating the tags. I was thinking that I could do an onblur somewhere in the bootstrap-tagsinput.js file.

Can someone assist?

bootstrap tagsinput

Thanks.

回答1:

You can modify the plugin itself (bootstratp-tagsinput.js) and add on blur event (I pretty much copied this one from on keydown event):

self.$container.on('blur', 'input', $.proxy(function(event) {
    var $input = $(event.target);

      if (self.options.freeInput) {
        self.add($input.val());
        $input.val('');
        event.preventDefault();
      }

      // Reset internal input's size
      $input.attr('size', Math.max(this.inputSize, $input.val().length));
    }, self));