// [script type="text/javascript" src="select_multiple.js"][/script]
// javascript:(function(){ let s = document.createElement('script'); s.src = 'select_multiple.js'; (document.head || document.body).appendChild(s); })();
// TODO: document what it does
// TODO maybe not auto-init? that way you can config things before init.
// TODO default selector currently 'select[multiple]' , maybe 'select[multiple].select_multiple' ?
// TODO only show filter when select (or filter) has focus?
// TODO selected values summary? when do we show this? and where? optional?
// TODO if something removes the original select, the search and summary element added here will linger. fix that. see SelectSearchMap and SelectSummaryMap
// TODO handle optgroup (e.g. show/hide group if something/nothing selected in it)
(function(){
function init_css() {
let css = `
select[multiple] {
transition: all 1s;
min-width: 100px;
min-height: 20px;
/* allow room to click empty space without changing selected options: */
padding-top: 1.5em;
padding-bottom: 0;
}
select[multiple].focus,
select[multiple]:focus {
min-width: 50vw !important;
min-height: 50vh !important;
}
select[multiple]:not(:focus, .focus) optgroup.selected_0 ,
select[multiple]:not(:focus, .focus) option.selected_0 {
display: none;
}
.select_multiple_search {
display: block;
}
`;
document.querySelector('style#style_select_multiple')?.remove();
let style = document.createElement('style');
style.id = 'style_select_multiple';
(document.head || document.body).appendChild(style);
style.innerText = css;
}
let SelectSearchMap = new Map();
function init_select_multiple_search(el_select) {
// NB: assigning to HTMLElement property is bad practice (possible namespace collision).
// Use private var instead. Map() allows object keys.
// TODO: wrap both select and search in one display: inline-block element.
if (SelectSearchMap.get(el_select)) {
return;
}
let el_search =...
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.