Skip to content

Commit

Permalink
Fix #42: Fix plugin bug that prevents clearing Select2 input correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Jun 4, 2015
1 parent 7198539 commit d313652
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
version 2.0.1
=============
**Date:** 12-May-2015
**Date:** 04-Jun-2015

- (enh #28): Better width style validation for Select2.
- (enh #32): More correct language validation.
- (enh #34): Better initialization for `data` and `multiple` ajax select.
- (bug #42): Fix plugin bug that prevents clearing Select2 input correctly.

version 2.0.0
=============
Expand Down
6 changes: 2 additions & 4 deletions Select2.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,10 @@ public function registerAssets()
{
$id = $this->options['id'];
$this->registerAssetBundle();
// validate bootstrap has-success & has-error states
$clear = 'kv_close_' . str_replace('-', '_', $id);
// do not open dropdown when clear icon is pressed to clear value
$this->pluginEvents += [
'select2:opening' => "function(event){initSelect2DropStyle('{$id}', '{$clear}', event);}",
'select2:unselect' => "function(){window.{$clear} = true;}"
'select2:opening' => "function(event){initSelect2DropStyle('{$id}');}",
'select2:unselecting' => "function(){\$(this).data('unselecting', true);}"
];
// register plugin
if ($this->pluginLoading) {
Expand Down
10 changes: 6 additions & 4 deletions lib/js/select2-krajee.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
}
$loading.remove();
};
initSelect2DropStyle = function (id, clear, event) {
initSelect2DropStyle = function (id) {
var $el = $('#' + id), $drop = $(".select2-container--open"),
cssClasses, i, $src = $el.parents("[class*='has-']");
if ($src.length) {
Expand All @@ -32,9 +32,11 @@
}
}
}
if (window[clear]) {
event.preventDefault();
window[clear] = false;
if ($el.data('unselecting')) {
$el.removeData('unselecting');
setTimeout(function() {
$el.select2('close')
}, 1);
}
};
})(jQuery);
2 changes: 1 addition & 1 deletion lib/js/select2-krajee.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
* Author: Kartik Visweswaran
* For more JQuery plugins visit http://plugins.krajee.com
* For more Yii related demos visit http://demos.krajee.com
*/!function(e){initSelect2Loading=function(n,s){var a=e("#"+n),o=e(s),t=e(".kv-plugin-loading.loading-"+n),i=e(".group-"+n);o.length||a.show(),i.length&&i.removeClass("kv-input-group-hide").removeClass(".group-"+n),t.remove()},initSelect2DropStyle=function(n,s,a){var o,t,i=e("#"+n),l=e(".select2-container--open"),r=i.parents("[class*='has-']");if(r.length)for(o=r[0].className.split(/\s+/),t=0;t<o.length;t++)o[t].match("has-")&&l.removeClass("has-success has-error has-warning").addClass(o[t]);window[s]&&(a.preventDefault(),window[s]=!1)}}(jQuery);
*/!function(e){initSelect2Loading=function(s,n){var a=e("#"+s),t=e(n),o=e(".kv-plugin-loading.loading-"+s),l=e(".group-"+s);t.length||a.show(),l.length&&l.removeClass("kv-input-group-hide").removeClass(".group-"+s),o.remove()},initSelect2DropStyle=function(s){var n,a,t=e("#"+s),o=e(".select2-container--open"),l=t.parents("[class*='has-']");if(l.length)for(n=l[0].className.split(/\s+/),a=0;a<n.length;a++)n[a].match("has-")&&o.removeClass("has-success has-error has-warning").addClass(n[a]);t.data("unselecting")&&(t.removeData("unselecting"),setTimeout(function(){t.select2("close")},1))}}(jQuery);

0 comments on commit d313652

Please sign in to comment.