var anyStatus =new Array("1","2","3","4","5","6");
$(document).ready(function() {
$('#status').select2().on('select2:select', function (e) {
if(e.params.data.selected && e.params.data.id == 'a') {
// the last option added was 'any'
// clear out the other previously selected
// options
$('#status').val(['a']).trigger('change');
return;
} else {
// something other than 'any' was selected
var left = new Array;
var a = $('#status').find(':selected')
var needUpdate = 0;
// scan through selected options to weed
// out 'any'
$.each(a,function(){
var v = this.value;
// leave out any
if(v != 'a') {
left.push(v);
needUpdate = 1;
}
})
if( JSON.stringify(left)==JSON.stringify(anyStatus) ) {
// all the status were turned on, so
// short circuit back to any.
$('#status').val(['a']).trigger('change');
} else if(needUpdate) {
// update selected options to list
// without 'any' selected
$('#status').val(left).trigger('change');
}
}
});
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.