Last active
September 9, 2016 11:30
-
-
Save leedohyung-dba/2fa1b75306f76881a6db448209b0b4be to your computer and use it in GitHub Desktop.
[JavaScript]jQueryプラグイン、select2を始める!そして、select2の改善事項 ref: http://qiita.com/leedohyung-dba/items/af6fe5880a2f5d071b56
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(".user_list").select2({ | |
closeOnSelect : false | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var select2u = { | |
//このObjectの全判に扱う要素を定義する | |
$select2: null, | |
$select2OnlyDisplay: null, | |
//メインのjQueryプラグインSelect2の要素に設定する | |
setInit: function(targetClassName) { | |
select2u.$select2 = $("."+targetClassName).select2({ /* options */ }); | |
}, | |
//タグ表示のみの要素の設定する | |
setOnlyDisplayInit: function(targetClassNameToOnlyDisplay) { | |
return new Promise((resolve, reject) => { | |
select2u.$select2OnlyDisplay = $("."+targetClassNameToOnlyDisplay).select2({ | |
// allowClear: true, | |
// tags: true, | |
//PulldownListが表示されないように何もしない | |
templateResult: function (data) {} | |
}); | |
}); | |
}, | |
setSelect2SelectEventHandler: function() { | |
select2u.$select2.on("select2:select", function (e) { | |
select2u.getEventCtl(e); | |
}); | |
}, | |
setSelect2UnSelectEventHandler: function() { | |
select2u.$select2.on("select2:unselect", function (e) { | |
select2u.getEventCtl(e); | |
}); | |
}, | |
//selectとunselectの場合の処理が一緒で、違うパラメーターだけ渡す | |
getEventCtl: function(e) { | |
select2u.$select2OnlyDisplay.val(select2u.$select2.val()).trigger("change"); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment