Destory chosen when hidden elements are shown

This commit is contained in:
David Craig 2015-04-21 12:46:41 +12:00
parent 8e301c4884
commit add7e136b7
1 changed files with 16 additions and 21 deletions

View File

@ -10,7 +10,6 @@
*/
$.fn.chosenDestroy = function () {
$(this)
.show()
.removeClass('chzn-done')
.removeClass('has-chzn')
.next()
@ -21,31 +20,27 @@
$.entwine('ss', function($) {
$('.silverstripe-tag-field').entwine({
'onadd': function() {
var $this = $(this);
$('.silverstripe-tag-field + .chzn-container').entwine({
onmatch: function() {
var $select = $(this).prev();
$select
.chosenDestroy()
.select2({
'tags': true,
'tokenSeparators': [',', ' ']
});
/*
* Delay a cycle so we don't see 2 inputs...
* Delay a cycle so select2 is initialised before
* selecting values (if data-selected-values is present).
*/
setTimeout(function () {
$this.chosenDestroy()
.select2({
'tags': true,
'tokenSeparators': [',', ' ']
});
if ($select.attr('data-selected-values')) {
var values = $select.attr('data-selected-values');
/*
* Delay a cycle so select2 is initialised before
* selecting values (if data-selected-values is present).
*/
setTimeout(function () {
if ($this.attr('data-selected-values')) {
var values = $this.attr('data-selected-values');
$this.select2('val', values.split(','));
}
}, 0);
$select.select2('val', values.split(','));
}
}, 0);
}
});