1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SELECT2 検索ボックスの削除ボタンのバブリングやってみた

Posted at

#前書き

select2を使っていて、検索ボックスで一回名前を選択した後にやっぱり消そう~てなって消したときにプルダウンが開いてしまうのが気になったので今回やってみました!

※jsファイルに記述を足す必要があるのでダウンロードしている前提で書きます

#手順
① jsファイルを開き1541行目までいく
そうするとこんな感じの記述が↓

this.$selection.on('click', '.select2-selection__choice__remove',
    function (evt) {
    var $remove = $(this);
    var $selection = $remove.parent();
    
        var data = $selection.data('data');

    self.trigger('unselect', {
      originalEvent: evt,
      data: data
    });
  });
};

② 後はfunction(evt)内に evt.stopPropagation();を記述して終わりです

 this.$selection.on('click', '.select2-selection__choice__remove',
        function (evt) {
            var $remove = $(this);
            var $selection = $remove.parent();

            evt.stopPropagation();

            var data = $selection.data('data');

            self.trigger('unselect', {
                originalEvent: evt,
                data: data
            });
        });

#最後に
初投稿でおかしな点もあるかもなのでもしありましたら教えてもらえると幸いです。
以上

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?