0},e.prototype.getChoiceById=function(e){return this.activeChoices.find((function(t){return t.id===e}))},e.prototype.getGroupById=function(e){return this.groups.find((function(t){return t.id===e}))},e}(),B=function(e,t){return e?function(e){if("string"==typeof e)return e;if("object"==typeof e){if("escaped"in e)return e.escaped;if("trusted"in e)return e.trusted}return""}(t):l(t)},k=function(e,t){if(t){var i=e.dataset;"string"==typeof t?i.customProperties=t:"object"!=typeof t||function(e){for(var t in e)if(Object.prototype.hasOwnProperty.call(e,t))return!1;return!0}(t)||(i.customProperties=JSON.stringify(t))}},K={containerOuter:function(e,t,i,n,s,o,r){var a=e.classNames.containerOuter,c=Object.assign(document.createElement("div"),{className:p(a).join(" ")});return c.dataset.type=o,t&&(c.dir=t),n&&(c.tabIndex=0),i&&(c.setAttribute("role",s?"combobox":"listbox"),s&&c.setAttribute("aria-autocomplete","list")),c.setAttribute("aria-haspopup","true"),c.setAttribute("aria-expanded","false"),r&&c.setAttribute("aria-labelledby",r),c},containerInner:function(e){var t=e.classNames.containerInner;return Object.assign(document.createElement("div"),{className:p(t).join(" ")})},itemList:function(e,t){var i=e.classNames,n=i.list,s=i.listSingle,o=i.listItems;return Object.assign(document.createElement("div"),{className:"".concat(p(n).join(" ")," ").concat(t?p(s).join(" "):p(o).join(" "))})},placeholder:function(e,t){var i=e.allowHTML,n=e.classNames.placeholder;return Object.assign(document.createElement("div"),{className:p(n).join(" "),innerHTML:B(i,t)})},item:function(e,t,i){var n,s,o,r=e.allowHTML,a=e.removeItemButtonAlignLeft,c=e.classNames,h=c.item,u=c.button,d=c.highlightedState,m=c.itemSelectable,f=c.placeholder,v=t.id,g=t.value,_=t.label,y=t.labelClass,b=t.labelDescription,E=t.customProperties,C=t.active,I=t.disabled,w=t.highlighted,S=t.placeholder,O=Object.assign(document.createElement("div"),{className:p(h).join(" ")});if(y){var A=Object.assign(document.createElement("span"),{innerHTML:B(r,_),className:p(y).join(" ")});O.appendChild(A)}else O.innerHTML=B(r,_);if(Object.assign(O.dataset,{item:"",id:v,value:g}),y&&(O.dataset.labelClass=p(y).join(" ")),b&&(O.dataset.labelDescription=b),k(O,E),C&&O.setAttribute("aria-selected","true"),I&&O.setAttribute("aria-disabled","true"),S&&((n=O.classList).add.apply(n,p(f)),O.dataset.placeholder=""),(s=O.classList).add.apply(s,p(w?d:m)),i){I&&(o=O.classList).remove.apply(o,p(m)),O.dataset.deletable="";var T="function"==typeof this.config.removeItemIconText?this.config.removeItemIconText(l(g),g):this.config.removeItemIconText,L="function"==typeof this.config.removeItemLabelText?this.config.removeItemLabelText(l(g),g):this.config.removeItemLabelText,D=Object.assign(document.createElement("button"),{type:"button",className:p(u).join(" "),innerHTML:T});D.setAttribute("aria-label",L),D.dataset.button="",a?O.insertAdjacentElement("afterbegin",D):O.appendChild(D)}return O},choiceList:function(e,t){var i=e.classNames.list,n=Object.assign(document.createElement("div"),{className:p(i).join(" ")});return t||n.setAttribute("aria-multiselectable","true"),n.setAttribute("role","listbox"),n},choiceGroup:function(e,t){var i=e.allowHTML,n=e.classNames,s=n.group,o=n.groupHeading,r=n.itemDisabled,a=t.id,c=t.label,l=t.disabled,h=Object.assign(document.createElement("div"),{className:"".concat(p(s).join(" ")," ").concat(l?p(r).join(" "):"")});return h.setAttribute("role","group"),Object.assign(h.dataset,{group:"",id:a,value:c}),l&&h.setAttribute("aria-disabled","true"),h.appendChild(Object.assign(document.createElement("div"),{className:p(o).join(" "),innerHTML:B(i,c)})),h},choice:function(e,t,i){var n,s,o,r,a,c=e.allowHTML,l=e.classNames,h=l.item,u=l.itemChoice,d=l.itemSelectable,m=l.selectedState,f=l.itemDisabled,v=l.description,g=l.placeholder,_=t.id,y=t.value,b=t.label,E=t.groupId,C=t.elementId,I=t.labelClass,w=t.labelDescription,S=t.disabled,O=t.selected,A=t.placeholder,T=Object.assign(document.createElement("div"),{id:C,className:"".concat(p(h).join(" ")," ").concat(p(u).join(" "))}),L=T;if(I){var D=Object.assign(document.createElement("span"),{innerHTML:B(c,b),className:p(I).join(" ")});L=D,T.appendChild(D)}else T.innerHTML=B(c,b);if(w){var N="".concat(C,"-description");L.setAttribute("aria-describedby",N);var x=Object.assign(document.createElement("span"),{innerHTML:B(c,w),id:N});(n=x.classList).add.apply(n,p(v)),T.appendChild(x)}return O&&(s=T.classList).add.apply(s,p(m)),A&&(o=T.classList).add.apply(o,p(g)),T.setAttribute("role",E&&E>0?"treeitem":"option"),Object.assign(T.dataset,{choice:"",id:_,value:y,selectText:i}),I&&(T.dataset.labelClass=p(I).join(" ")),w&&(T.dataset.labelDescription=w),S?((r=T.classList).add.apply(r,p(f)),T.dataset.choiceDisabled="",T.setAttribute("aria-disabled","true")):((a=T.classList).add.apply(a,p(d)),T.dataset.choiceSelectable=""),T},input:function(e,t){var i=e.classNames,n=i.input,s=i.inputCloned,o=Object.assign(document.createElement("input"),{type:"search",className:"".concat(p(n).join(" ")," ").concat(p(s).join(" ")),autocomplete:"off",autocapitalize:"off",spellcheck:!1});return o.setAttribute("role","textbox"),o.setAttribute("aria-autocomplete","list"),t&&o.setAttribute("aria-label",t),o},dropdown:function(e){var t,i,n=e.classNames,s=n.list,o=n.listDropdown,r=document.createElement("div");return(t=r.classList).add.apply(t,p(s)),(i=r.classList).add.apply(i,p(o)),r.setAttribute("aria-expanded","false"),r},notice:function(e,t,i){var s=e.allowHTML,o=e.classNames,r=o.item,a=o.itemChoice,c=o.addChoice,l=o.noResults,h=o.noChoices;void 0===i&&(i="");var u=n(n([],p(r),!0),p(a),!0);switch(i){case"add-choice":u.push.apply(u,p(c));break;case"no-results":u.push.apply(u,p(l));break;case"no-choices":u.push.apply(u,p(h))}var d=Object.assign(document.createElement("div"),{innerHTML:B(s,t),className:u.join(" ")});return"add-choice"===i&&(d.dataset.choiceSelectable="",d.dataset.choice=""),d},option:function(e){var t=e.label,i=e.value,n=e.labelClass,s=e.labelDescription,o=e.customProperties,r=e.active,a=e.disabled,c=u(t),l=new Option(c,i,!1,r);return n&&(l.dataset.labelClass=p(n).join(" ")),s&&(l.dataset.labelDescription=s),k(l,o),l.disabled=a,l}},U="-ms-scroll-limit"in document.documentElement.style&&"-ms-ime-align"in document.documentElement.style,q={},G=function(e){if(e){var t=e.dataset.id;return t?parseInt(t,10):void 0}},W=function(){function e(t,n){void 0===t&&(t="[data-choice]"),void 0===n&&(n={});var s=this;this._hasNonChoicePlaceholder=!1,this._lastAddedChoiceId=0,this._lastAddedGroupId=0,this.config=i(i(i({},e.defaults.allOptions),e.defaults.options),n),D.forEach((function(t){s.config[t]=i(i(i({},e.defaults.allOptions[t]),e.defaults.options[t]),n[t])}));var r,a,l,h,u=(r=this.config,a=L,l=Object.keys(r).sort(),h=Object.keys(a).sort(),l.filter((function(e){return h.indexOf(e)<0})));u.length&&console.warn("Unknown config option(s) passed",u.join(", ")),!this.config.silent&&this.config.allowHTML&&this.config.allowHtmlUserInput&&(this.config.addItems&&console.warn("Warning: allowHTML/allowHtmlUserInput/addItems all being true is strongly not recommended and may lead to XSS attacks"),this.config.addChoices&&console.warn("Warning: allowHTML/allowHtmlUserInput/addChoices all being true is strongly not recommended and may lead to XSS attacks"));var d=this.config.shadowRoot||document.documentElement,p="string"==typeof t?d.querySelector(t):t;if(!p||"object"!=typeof p||"INPUT"!==p.tagName&&!function(e){return"SELECT"===e.tagName}(p)){if(!p&&"string"==typeof t)throw TypeError("Selector ".concat(t," failed to find an element"));throw TypeError("Expected one of the following types text|select-one|select-multiple")}if(this._elementType=p.type,this._isTextElement=this._elementType===g,(this._isTextElement||1!==this.config.maxItemCount)&&(this.config.singleModeForMultiSelect=!1),this.config.singleModeForMultiSelect&&(this._elementType=y),this._isSelectOneElement=this._elementType===_,this._isSelectMultipleElement=this._elementType===y,this._isSelectElement=this._isSelectOneElement||this._isSelectMultipleElement,this._canAddUserChoices=this._isTextElement&&this.config.addItems||this._isSelectElement&&this.config.addChoices,["auto","always"].includes("".concat(this.config.renderSelectedChoices))||(this.config.renderSelectedChoices="auto"),this.config.placeholder&&(this.config.placeholderValue?this._hasNonChoicePlaceholder=!0:p.dataset.placeholder&&(this._hasNonChoicePlaceholder=!0,this.config.placeholderValue=p.dataset.placeholder)),n.addItemFilter&&"function"!=typeof n.addItemFilter){var m=n.addItemFilter instanceof RegExp?n.addItemFilter:new RegExp(n.addItemFilter);this.config.addItemFilter=m.test.bind(m)}if(this._isTextElement)this.passedElement=new w({element:p,classNames:this.config.classNames});else{var f=p;this.passedElement=new T({element:f,classNames:this.config.classNames,template:function(e){return s._templates.option(e)},extractPlaceholder:this.config.placeholder&&!this._hasNonChoicePlaceholder})}if(this.initialised=!1,this._store=new V,this._initialState=M,this._currentState=M,this._prevState=M,this._currentValue="",this.config.searchEnabled=!this._isTextElement&&this.config.searchEnabled||this._elementType===y,this._canSearch=this.config.searchEnabled,this._isScrollingOnIe=!1,this._highlightPosition=0,this._wasTap=!0,this._placeholderValue=this._generatePlaceholderValue(),this._baseId=function(e,t){var i=e.id||e.name&&"".concat(e.name,"-").concat(c(2))||c(4);return i=i.replace(/(:|\.|\[|\]|,)/g,""),"".concat(t,"-").concat(i)}(this.passedElement.element,"choices-"),this._searchFn=o,this._direction=this.passedElement.dir,!this._direction){var v=window.getComputedStyle(this.passedElement.element).direction;v!==window.getComputedStyle(document.documentElement).direction&&(this._direction=v)}if(this._idNames={itemChoice:"item-choice"},this._render=this._render.bind(this),this._onFocus=this._onFocus.bind(this),this._onBlur=this._onBlur.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onInput=this._onInput.bind(this),this._onClick=this._onClick.bind(this),this._onTouchMove=this._onTouchMove.bind(this),this._onTouchEnd=this._onTouchEnd.bind(this),this._onMouseDown=this._onMouseDown.bind(this),this._onMouseOver=this._onMouseOver.bind(this),this._onFormReset=this._onFormReset.bind(this),this._onSelectKey=this._onSelectKey.bind(this),this._onEnterKey=this._onEnterKey.bind(this),this._onEscapeKey=this._onEscapeKey.bind(this),this._onDirectionKey=this._onDirectionKey.bind(this),this._onDeleteKey=this._onDeleteKey.bind(this),this.passedElement.isActive)return this.config.silent||console.warn("Trying to initialise Choices on element already initialised",{element:t}),void(this.initialised=!0);this.init(),this._initialItems=this._store.items.map((function(e){return e.value}))}return Object.defineProperty(e,"defaults",{get:function(){return Object.preventExtensions({get options(){return q},get allOptions(){return L},get templates(){return K}})},enumerable:!1,configurable:!0}),e.prototype.init=function(){if(!this.initialised){this._loadChoices(),this._createTemplates(),this._createElements(),this._createStructure(),this._store.subscribe(this._render),this._render(),this._addEventListeners(),(this._isTextElement&&!this.config.addItems||this._isSelectElement&&!this.config.addChoices&&0===this._store.choices.length||this.passedElement.element.hasAttribute("disabled")||!!this.passedElement.element.closest("fieldset:disabled"))&&this.disable(),this.initialised=!0;var e=this.config.callbackOnInit;e&&"function"==typeof e&&e.call(this)}},e.prototype.destroy=function(){this.initialised&&(this._removeEventListeners(),this.passedElement.reveal(),this.containerOuter.unwrap(this.passedElement.element),this.clearStore(),this._stopSearch(),this._templates=K,this.initialised=!1)},e.prototype.enable=function(){return this.passedElement.isDisabled&&this.passedElement.enable(),this.containerOuter.isDisabled&&(this._addEventListeners(),this.input.enable(),this.containerOuter.enable()),this},e.prototype.disable=function(){return this.passedElement.isDisabled||this.passedElement.disable(),this.containerOuter.isDisabled||(this._removeEventListeners(),this.input.disable(),this.containerOuter.disable()),this},e.prototype.highlightItem=function(e,t){if(void 0===t&&(t=!0),!e||!e.id)return this;var i=this._store.choices.find((function(t){return t.id===e.id}));return!i||i.highlighted||(this._store.dispatch(r(i,!0)),t&&this.passedElement.triggerEvent("highlightItem",this._getChoiceForOutput(i))),this},e.prototype.unhighlightItem=function(e,t){if(void 0===t&&(t=!0),!e||!e.id)return this;var i=this._store.choices.find((function(t){return t.id===e.id}));return i&&i.highlighted?(this._store.dispatch(r(i,!1)),t&&this.passedElement.triggerEvent("highlightItem",this._getChoiceForOutput(i)),this):this},e.prototype.highlightAll=function(){var e=this;return this._store.withDeferRendering((function(){e._store.items.forEach((function(t){return e.highlightItem(t)}))})),this},e.prototype.unhighlightAll=function(){var e=this;return this._store.withDeferRendering((function(){e._store.items.forEach((function(t){return e.unhighlightItem(t)}))})),this},e.prototype.removeActiveItemsByValue=function(e){var t=this;return this._store.withDeferRendering((function(){t._store.items.filter((function(t){return t.value===e})).forEach((function(e){return t._removeItem(e)}))})),this},e.prototype.removeActiveItems=function(e){var t=this;return this._store.withDeferRendering((function(){t._store.items.filter((function(t){return t.id!==e})).forEach((function(e){return t._removeItem(e)}))})),this},e.prototype.removeHighlightedItems=function(e){var t=this;return void 0===e&&(e=!1),this._store.withDeferRendering((function(){t._store.highlightedActiveItems.forEach((function(i){t._removeItem(i),e&&t._triggerChange(i.value)}))})),this},e.prototype.showDropdown=function(e){var t=this;return this.dropdown.isActive||requestAnimationFrame((function(){t.dropdown.show(),t.containerOuter.open(t.dropdown.distanceFromTopWindow),!e&&t._canSearch&&t.input.focus(),t.passedElement.triggerEvent("showDropdown",{})})),this},e.prototype.hideDropdown=function(e){var t=this;return this.dropdown.isActive?(requestAnimationFrame((function(){t.dropdown.hide(),t.containerOuter.close(),!e&&t._canSearch&&(t.input.removeActiveDescendant(),t.input.blur()),t.passedElement.triggerEvent("hideDropdown",{})})),this):this},e.prototype.getValue=function(e){var t=this;void 0===e&&(e=!1);var i=this._store.items.reduce((function(i,n){var s=e?n.value:t._getChoiceForOutput(n);return i.push(s),i}),[]);return this._isSelectOneElement||this.config.singleModeForMultiSelect?i[0]:i},e.prototype.setValue=function(e){var t=this;return this.initialised?(this._store.withDeferRendering((function(){e.forEach((function(e){e&&t._addChoice(A(e,!1))}))})),this):this},e.prototype.setChoiceByValue=function(e){var t=this;return!this.initialised||this._isTextElement||this._store.withDeferRendering((function(){(Array.isArray(e)?e:[e]).forEach((function(e){return t._findAndSelectChoiceByValue(e)}))})),this},e.prototype.setChoices=function(e,t,n,s){var o=this;if(void 0===e&&(e=[]),void 0===t&&(t="value"),void 0===n&&(n="label"),void 0===s&&(s=!1),!this.initialised)throw new ReferenceError("setChoices was called on a non-initialized instance of Choices");if(!this._isSelectElement)throw new TypeError("setChoices can't be used with INPUT based Choices");if("string"!=typeof t||!t)throw new TypeError("value parameter must be a name of 'value' field in passed objects");if(s&&this.clearChoices(),"function"==typeof e){var r=e(this);if("function"==typeof Promise&&r instanceof Promise)return new Promise((function(e){return requestAnimationFrame(e)})).then((function(){return o._handleLoadingState(!0)})).then((function(){return r})).then((function(e){return o.setChoices(e,t,n,s)})).catch((function(e){o.config.silent||console.error(e)})).then((function(){return o._handleLoadingState(!1)})).then((function(){return o}));if(!Array.isArray(r))throw new TypeError(".setChoices first argument function must return either array of choices or Promise, got: ".concat(typeof r));return this.setChoices(r,t,n,!1)}if(!Array.isArray(e))throw new TypeError(".setChoices must be called either with array of choices with a function resulting into Promise of array of choices");return this.containerOuter.removeLoadingState(),this._store.withDeferRendering((function(){var s="value"===t,r="label"===n;e.forEach((function(e){if("choices"in e){var a=e;r||(a=i(i({},a),{label:a[n]})),o._addGroup(A(a,!0))}else{var c=e;r&&s||(c=i(i({},c),{value:c[t],label:c[n]})),o._addChoice(A(c,!1))}}))})),this},e.prototype.refresh=function(e,t,i){var n=this;return void 0===e&&(e=!1),void 0===t&&(t=!1),void 0===i&&(i=!1),this._isSelectElement?(this._store.withDeferRendering((function(){var s=n.passedElement.optionsAsChoices(),o=n._store.items,r={};i||o.forEach((function(e){e.id&&e.active&&e.selected&&!e.disabled&&(r[e.value]=!0)})),s.forEach((function(e){if(!("choices"in e)){var t=e;i?t.selected=!1:r[t.value]&&(t.selected=!0)}})),n.clearStore(),n._addPredefinedChoices(s,t,e),n._isSearching&&n._searchChoices(n.input.value)})),this):(this.config.silent||console.warn("refresh method can only be used on choices backed by a element"),this)},e.prototype.removeChoice=function(e){var t=this._store.choices.find((function(t){return t.value===e}));return t?(this._store.dispatch(function(e){return{type:"REMOVE_CHOICE",choice:e}}(t)),t.selected&&this.passedElement.triggerEvent("removeItem",this._getChoiceForOutput(t)),this):this},e.prototype.clearChoices=function(){return this._store.dispatch({type:"CLEAR_CHOICES"}),this},e.prototype.clearStore=function(){return this._store.dispatch({type:"CLEAR_ALL"}),this._lastAddedChoiceId=0,this._lastAddedGroupId=0,this},e.prototype.clearInput=function(){var e=!this._isSelectOneElement;return this.input.clear(e),this._isSearching&&this._stopSearch(),this},e.prototype._render=function(){if(!this._store.isLoading()){this._currentState=this._store.state;var e=this._currentState.items!==this._prevState.items;(this._currentState.choices!==this._prevState.choices||this._currentState.groups!==this._prevState.groups||e)&&(this._isSelectElement&&this._renderChoices(),e&&this._renderItems(),this._prevState=this._currentState)}},e.prototype._renderChoices=function(){var e=this,t=this._store,i=t.activeGroups,n=t.activeChoices,s=document.createDocumentFragment();if(this.choiceList.clear(),this.config.resetScrollPosition&&requestAnimationFrame((function(){return e.choiceList.scrollToTop()})),i.length>=1&&!this._isSearching){var o=n.filter((function(e){return e.placeholder&&-1===e.groupId}));o.length>=1&&(s=this._createChoicesFragment(o,s)),s=this._createGroupsFragment(i,n,s)}else n.length>=1&&(s=this._createChoicesFragment(n,s));var r=this.input.value,a=this._canAddItem(this._store.items,r);if(s.childNodes&&s.childNodes.length>0){var c=!a.response;if(a.response&&(this.choiceList.append(s),this._highlightChoice(),this._canAddUserChoices&&r&&a.notice&&(c=!n.find((function(t){return e.config.valueComparer(t.value,r)})))),c){var l=this._templates.notice(this.config,a.notice,this._canAddUserChoices?"add-choice":"");this.choiceList.prepend(l)}}else{var h=void 0;if(a.response&&this._canAddUserChoices&&r)h=this._templates.notice(this.config,a.notice,"add-choice");else if(this._isSearching){l="function"==typeof this.config.noResultsText?this.config.noResultsText():this.config.noResultsText;h=this._templates.notice(this.config,l,"no-results")}else{l="function"==typeof this.config.noChoicesText?this.config.noChoicesText():this.config.noChoicesText;h=this._templates.notice(this.config,l,"no-choices")}this.choiceList.append(h)}},e.prototype._renderItems=function(){var e=this._store.items||[];this.itemList.clear();var t=this._createItemsFragment(e);t.childNodes&&this.itemList.append(t)},e.prototype._createGroupsFragment=function(e,t,i){var n=this;void 0===i&&(i=document.createDocumentFragment());this.config.shouldSort&&e.sort(this.config.sorter);var s=t.filter((function(e){return 0===e.groupId}));return s.length>0&&this._createChoicesFragment(s,i,!1),e.forEach((function(e){var s=function(e){return t.filter((function(t){return n._isSelectOneElement?t.groupId===e.id:t.groupId===e.id&&("always"===n.config.renderSelectedChoices||!t.selected)}))}(e);if(s.length>=1){var o=n._templates.choiceGroup(n.config,e);i.appendChild(o),n._createChoicesFragment(s,i,!0)}})),i},e.prototype._createChoicesFragment=function(e,t,i){var s=this;void 0===t&&(t=document.createDocumentFragment()),void 0===i&&(i=!1);var o=this.config,r=o.renderSelectedChoices,a=o.searchResultLimit,c=o.renderChoiceLimit,l=o.appendGroupInSearch,h=this._isSearching?d:this.config.sorter,u=function(e){if("auto"!==r||(s._isSelectOneElement||!e.selected)){var i=s._templates.choice(s.config,e,s.config.itemSelectText);if(l){var n="";s._store.groups.every((function(t){return t.id!==e.groupId||(n=t.label,!1)})),n&&s._isSearching&&(i.innerHTML+=" (".concat(n,")"))}t.appendChild(i)}},p=e;if("auto"!==r||this._isSelectOneElement||(p=e.filter((function(e){return!e.selected}))),this._isSelectElement){var m=e.filter((function(e){return!e.element}));0!==m.length&&this.passedElement.addOptions(m)}var f=p.reduce((function(e,t){return t.placeholder?e.placeholderChoices.push(t):e.normalChoices.push(t),e}),{placeholderChoices:[],normalChoices:[]}),v=f.placeholderChoices,g=f.normalChoices;(this.config.shouldSort||this._isSearching)&&g.sort(h);var _=p.length,y=this._isSelectOneElement?n(n([],v,!0),g,!0):g;this._isSearching?_=a:c&&c>0&&!i&&(_=c);for(var b=0;b<_;b+=1)y[b]&&u(y[b]);return t},e.prototype._createItemsFragment=function(e,t){var i=this;void 0===t&&(t=document.createDocumentFragment());var n=this.config,s=n.shouldSortItems,o=n.sorter,r=n.removeItemButton;s&&!this._isSelectOneElement&&e.sort(o),this._isTextElement&&(this.passedElement.value=e.map((function(e){return e.value})).join(this.config.delimiter));var a=function(e){var n=i._templates.item(i.config,e,r);t.appendChild(n)};return e.forEach(a),this._isSelectOneElement&&this._hasNonChoicePlaceholder&&0===e.length&&a(A({selected:!0,value:"",label:this.config.placeholderValue||"",active:!0,placeholder:!0},!1)),t},e.prototype._getChoiceForOutput=function(e,t){if(e){var i=e.groupId>0?this._store.getGroupById(e.groupId):null;return{id:e.id,highlighted:e.highlighted,labelClass:e.labelClass,labelDescription:e.labelDescription,customProperties:e.customProperties,disabled:e.disabled,active:e.active,label:e.label,placeholder:e.placeholder,value:e.value,groupValue:i&&i.label?i.label:void 0,element:e.element,keyCode:t}}},e.prototype._triggerChange=function(e){null!=e&&this.passedElement.triggerEvent("change",{value:e})},e.prototype._selectPlaceholderChoice=function(e){this._addItem(e),e.value&&this._triggerChange(e.value)},e.prototype._handleButtonAction=function(e,t){if(0!==e.length&&this.config.removeItems&&this.config.removeItemButton){var i=t&&G(t.parentNode),n=i&&e.find((function(e){return e.id===i}));if(n&&(this._removeItem(n),this._triggerChange(n.value),this._isSelectOneElement&&!this._hasNonChoicePlaceholder)){var s=this._store.placeholderChoice;s&&this._selectPlaceholderChoice(s)}}},e.prototype._handleItemAction=function(e,t,i){var n=this;if(void 0===i&&(i=!1),0!==e.length&&this.config.removeItems&&!this._isSelectOneElement){var s=G(t);s&&(e.forEach((function(e){e.id!==s||e.highlighted?!i&&e.highlighted&&n.unhighlightItem(e):n.highlightItem(e)})),this.input.focus())}},e.prototype._handleChoiceAction=function(e,t,i){var n=this,s=G(t),o=s&&this._store.getChoiceById(s);if(!o)return!1;var r=this.dropdown.isActive,a=!1;return this._store.withDeferRendering((function(){if(!o.selected&&!o.disabled&&n._canAddItem(e,o.value).response){if(n.config.singleModeForMultiSelect&&0!==e.length){var t=e[e.length-1];n._removeItem(t)}n.passedElement.triggerEvent("choice",n._getChoiceForOutput(o,i)),n._addItem(o),n.clearInput(),a=!0}})),!!a&&(this._triggerChange(o.value),r&&(this.config.singleModeForMultiSelect||this._isSelectOneElement)&&(this.hideDropdown(!0),this.containerOuter.focus()),!0)},e.prototype._handleBackspace=function(e){if(this.config.removeItems&&0!==e.length){var t=e[e.length-1],i=e.some((function(e){return e.highlighted}));this.config.editItems&&!i&&t?(this.input.value=t.value,this.input.setWidth(),this._removeItem(t),this._triggerChange(t.value)):(i||this.highlightItem(t,!1),this.removeHighlightedItems(!0))}},e.prototype._loadChoices=function(){var e;if(this._isTextElement){this._presetItems=this.config.items.map((function(e){return A(e,!1)}));var t=this.passedElement.value;if(t){var i=t.split(this.config.delimiter).map((function(e){return A(e,!1)}));this._presetItems=this._presetItems.concat(i)}this._presetItems.forEach((function(e){e.selected=!0}))}else if(this._isSelectElement){this._presetChoices=this.config.choices.map((function(e){return A(e,!0)}));var n=this.passedElement.optionsAsChoices();n&&(e=this._presetChoices).push.apply(e,n)}},e.prototype._startLoading=function(){this._store.startDeferRendering()},e.prototype._stopLoading=function(){this._store.stopDeferRendering()},e.prototype._handleLoadingState=function(e){void 0===e&&(e=!0);var t=this.itemList.element.querySelector(m(this.config.classNames.placeholder));e?(this.disable(),this.containerOuter.addLoadingState(),this._isSelectOneElement?t?t.innerHTML=this.config.loadingText:(t=this._templates.placeholder(this.config,this.config.loadingText))&&this.itemList.append(t):this.input.placeholder=this.config.loadingText):(this.enable(),this.containerOuter.removeLoadingState(),this._isSelectOneElement?t&&(t.innerHTML=this._placeholderValue||""):this.input.placeholder=this._placeholderValue||"")},e.prototype._handleSearch=function(e){if(this.input.isFocussed){var t=this._store.choices,i=this.config,n=i.searchFloor,s=i.searchChoices,o=t.some((function(e){return!e.active}));if(null!=e&&e.length>=n){var r=s?this._searchChoices(e):0;null!==r&&this.passedElement.triggerEvent("search",{value:e,resultCount:r})}else o&&this._stopSearch()}},e.prototype._canAddItem=function(e,t){var i=this,n=!0,s="";(this.config.maxItemCount>0&&this.config.maxItemCount<=e.length&&(this.config.singleModeForMultiSelect||(n=!1,s="function"==typeof this.config.maxItemText?this.config.maxItemText(this.config.maxItemCount):this.config.maxItemText)),n&&this._canAddUserChoices&&""!==t&&"function"==typeof this.config.addItemFilter&&!this.config.addItemFilter(t)&&(n=!1,s="function"==typeof this.config.customAddItemText?this.config.customAddItemText(l(t),t):this.config.customAddItemText),!n||""===t||!this._isSelectElement&&this.config.duplicateItemsAllowed)||this._store.items.find((function(e){return i.config.valueComparer(e.value,t)}))&&(n=!1,s="function"==typeof this.config.uniqueItemText?this.config.uniqueItemText(l(t),t):this.config.uniqueItemText);return n&&(s="function"==typeof this.config.addItemText?this.config.addItemText(l(t),t):this.config.addItemText),{response:n,notice:{trusted:s}}},e.prototype._searchChoices=function(e){var t=e.trim().replace(/\s{2,}/," ");if(0===t.length||t===this._currentValue)return null;var i=this._store.searchableChoices,n=this._searchFn(this.config,i,t);return this._currentValue=t,this._highlightPosition=0,this._isSearching=!0,this._store.dispatch(function(e){return{type:"FILTER_CHOICES",results:e}}(n)),n.length},e.prototype._stopSearch=function(){var e=this._isSearching;this._currentValue="",this._isSearching=!1,e&&this._store.dispatch({type:"ACTIVATE_CHOICES",active:!0})},e.prototype._addEventListeners=function(){var e=this.config.shadowRoot||document.documentElement;e.addEventListener("touchend",this._onTouchEnd,!0),this.containerOuter.element.addEventListener("keydown",this._onKeyDown,!0),this.containerOuter.element.addEventListener("mousedown",this._onMouseDown,!0),e.addEventListener("click",this._onClick,{passive:!0}),e.addEventListener("touchmove",this._onTouchMove,{passive:!0}),this.dropdown.element.addEventListener("mouseover",this._onMouseOver,{passive:!0}),this._isSelectOneElement&&(this.containerOuter.element.addEventListener("focus",this._onFocus,{passive:!0}),this.containerOuter.element.addEventListener("blur",this._onBlur,{passive:!0})),this.input.element.addEventListener("keyup",this._onKeyUp,{passive:!0}),this.input.element.addEventListener("input",this._onInput,{passive:!0}),this.input.element.addEventListener("focus",this._onFocus,{passive:!0}),this.input.element.addEventListener("blur",this._onBlur,{passive:!0}),this.input.element.form&&this.input.element.form.addEventListener("reset",this._onFormReset,{passive:!0}),this.input.addEventListeners()},e.prototype._removeEventListeners=function(){var e=this.config.shadowRoot||document.documentElement;e.removeEventListener("touchend",this._onTouchEnd,!0),this.containerOuter.element.removeEventListener("keydown",this._onKeyDown,!0),this.containerOuter.element.removeEventListener("mousedown",this._onMouseDown,!0),e.removeEventListener("click",this._onClick),e.removeEventListener("touchmove",this._onTouchMove),this.dropdown.element.removeEventListener("mouseover",this._onMouseOver),this._isSelectOneElement&&(this.containerOuter.element.removeEventListener("focus",this._onFocus),this.containerOuter.element.removeEventListener("blur",this._onBlur)),this.input.element.removeEventListener("keyup",this._onKeyUp),this.input.element.removeEventListener("input",this._onInput),this.input.element.removeEventListener("focus",this._onFocus),this.input.element.removeEventListener("blur",this._onBlur),this.input.element.form&&this.input.element.form.removeEventListener("reset",this._onFormReset),this.input.removeEventListeners()},e.prototype._onKeyDown=function(e){var t=e.keyCode,i=this._store.items,n=this.input.isFocussed,s=this.dropdown.isActive,o=this.itemList.hasChildren(),r=1===e.key.length||2===e.key.length&&e.key.charCodeAt(0)>=55296||"Unidentified"===e.key;switch(this._isTextElement||s||(this.showDropdown(),!this.input.isFocussed&&r&&(this.input.value+=e.key)),t){case 65:return this._onSelectKey(e,o);case 13:return this._onEnterKey(e,i,s);case 27:return this._onEscapeKey(e,s);case 38:case 33:case 40:case 34:return this._onDirectionKey(e,s);case 8:case 46:return this._onDeleteKey(e,i,n)}},e.prototype._onKeyUp=function(){this._canSearch=this.config.searchEnabled},e.prototype._onInput=function(){var e=this.input.value;if(e){if(this._isTextElement){var t=this._canAddItem(this._store.items,e);t.notice&&(this._displayAddItemNotice(t),this.showDropdown(!0))}if(this._canSearch){this._handleSearch(e);var i=this._canAddItem(this._store.items,e);i.response||this._displayAddItemNotice(i),this._canAddUserChoices&&(this._highlightPosition=0,this._highlightChoice())}}else this._isTextElement?this.hideDropdown(!0):this._stopSearch()},e.prototype._displayAddItemNotice=function(e){var t=this._templates.notice(this.config,e.notice,"add-choice"),i="".concat(m(this.config.classNames.addChoice),"[data-choice-selectable]"),n=this.choiceList.element.querySelector(i);n?n.outerHTML=t.outerHTML:this.choiceList.prepend(t)},e.prototype._onSelectKey=function(e,t){var i=e.ctrlKey,n=e.metaKey;(i||n)&&t&&(this._canSearch=!1,this.config.removeItems&&!this.input.value&&this.input.element===document.activeElement&&this.highlightAll())},e.prototype._onEnterKey=function(e,t,i){var n=this,s=this.input.value,o=e.target;if(o&&o.hasAttribute("data-button"))return e.preventDefault(),void this._handleButtonAction(t,o);if(!i&&this._isSelectOneElement)return e.preventDefault(),void this.showDropdown();if(i){var r=this.dropdown.element.querySelector(m(this.config.classNames.highlightedState));if(r&&this._handleChoiceAction(t,r,13))return e.preventDefault(),void this.unhighlightAll();s||this.hideDropdown(!0)}o&&s&&this._canAddUserChoices&&(this._canAddItem(t,s).response&&(this._store.withDeferRendering((function(){if((n._isSelectOneElement||n.config.singleModeForMultiSelect)&&0!==t.length){var e=t[t.length-1];n._removeItem(e)}var i=!0;if(!n._isSelectElement&&n.config.duplicateItemsAllowed||(i=!n._findAndSelectChoiceByValue(s)),i){var o=l(s),r=n.config.allowHtmlUserInput||o===s?s:{escaped:o,raw:s};n._addChoice(A({value:r,label:r,selected:!0},!1))}n.clearInput(),n.unhighlightAll(),n._triggerChange(s)})),(this._isTextElement||this._isSelectOneElement)&&this.hideDropdown(!0)))},e.prototype._onEscapeKey=function(e,t){t&&(e.stopPropagation(),this.hideDropdown(!0),this.containerOuter.focus())},e.prototype._onDirectionKey=function(e,t){var i,n,s,o=e.keyCode,r=e.metaKey;if(t||this._isSelectOneElement){this.showDropdown(),this._canSearch=!1;var a=40===o||34===o?1:-1,c="[data-choice-selectable]",l=void 0;if(r||34===o||33===o)l=a>0?this.dropdown.element.querySelector("".concat(c,":last-of-type")):this.dropdown.element.querySelector(c);else{var h=this.dropdown.element.querySelector(m(this.config.classNames.highlightedState));l=h?function(e,t,i){void 0===i&&(i=1);for(var n="".concat(i>0?"next":"previous","ElementSibling"),s=e[n];s;){if(s.matches(t))return s;s=s[n]}return s}(h,c,a):this.dropdown.element.querySelector(c)}l&&(i=l,n=this.choiceList.element,void 0===(s=a)&&(s=1),i&&(s>0?n.scrollTop+n.offsetHeight>=i.offsetTop+i.offsetHeight:i.offsetTop>=n.scrollTop)||this.choiceList.scrollToChildElement(l,a),this._highlightChoice(l)),e.preventDefault()}},e.prototype._onDeleteKey=function(e,t,i){var n=e.target;this._isSelectOneElement||n.value||!i||(this._handleBackspace(t),e.preventDefault())},e.prototype._onTouchMove=function(){this._wasTap&&(this._wasTap=!1)},e.prototype._onTouchEnd=function(e){var t=(e||e.touches[0]).target;this._wasTap&&this.containerOuter.element.contains(t)&&((t===this.containerOuter.element||t===this.containerInner.element)&&(this._isTextElement?this.input.focus():this._isSelectMultipleElement&&this.showDropdown()),e.stopPropagation());this._wasTap=!0},e.prototype._onMouseDown=function(e){var t=e.target;if(t instanceof HTMLElement){if(U&&this.choiceList.element.contains(t)){var i=this.choiceList.element.firstElementChild;this._isScrollingOnIe="ltr"===this._direction?e.offsetX>=i.offsetWidth:e.offsetX0&&this.unhighlightAll(),this.containerOuter.removeFocusState(),this.hideDropdown(!0))},e.prototype._onFocus=function(e){var t,i=this,n=e.target;n&&this.containerOuter.element.contains(n)&&((t={})[g]=function(){n===i.input.element&&i.containerOuter.addFocusState()},t[_]=function(){i.containerOuter.addFocusState(),n===i.input.element&&i.showDropdown(!0)},t[y]=function(){n===i.input.element&&(i.showDropdown(!0),i.containerOuter.addFocusState())},t)[this._elementType]()},e.prototype._onBlur=function(e){var t,i=this,n=e.target;if(n&&this.containerOuter.element.contains(n)&&!this._isScrollingOnIe){var s=this._store.activeChoices.some((function(e){return e.highlighted}));((t={})[g]=function(){n===i.input.element&&(i.containerOuter.removeFocusState(),s&&i.unhighlightAll(),i.hideDropdown(!0))},t[_]=function(){i.containerOuter.removeFocusState(),(n===i.input.element||n===i.containerOuter.element&&!i._canSearch)&&i.hideDropdown(!0)},t[y]=function(){n===i.input.element&&(i.containerOuter.removeFocusState(),i.hideDropdown(!0),s&&i.unhighlightAll())},t)[this._elementType]()}else this._isScrollingOnIe=!1,this.input.element.focus()},e.prototype._onFormReset=function(){var e=this;this._store.withDeferRendering((function(){e.clearInput(),e.hideDropdown(),e.refresh(!1,!1,!0),0!==e._initialItems.length&&e.setChoiceByValue(e._initialItems)}))},e.prototype._highlightChoice=function(e){var t,i=this;void 0===e&&(e=null);var n=Array.from(this.dropdown.element.querySelectorAll("[data-choice-selectable]"));if(n.length){var s=e;Array.from(this.dropdown.element.querySelectorAll(m(this.config.classNames.highlightedState))).forEach((function(e){var t;(t=e.classList).remove.apply(t,p(i.config.classNames.highlightedState)),e.setAttribute("aria-selected","false")})),s?this._highlightPosition=n.indexOf(s):(s=n.length>this._highlightPosition?n[this._highlightPosition]:n[n.length-1])||(s=n[0]),(t=s.classList).add.apply(t,p(this.config.classNames.highlightedState)),s.setAttribute("aria-selected","true"),this.passedElement.triggerEvent("highlightChoice",{el:s}),this.dropdown.isActive&&(this.input.setActiveDescendant(s.id),this.containerOuter.setActiveDescendant(s.id))}},e.prototype._addItem=function(e,t){void 0===t&&(t=!0);var i=e.id;if(0===i)throw new TypeError("item.id must be set before _addItem is called for a choice/item");this._store.dispatch(function(e){return{type:"ADD_ITEM",item:e}}(e)),this._isSelectOneElement&&this.removeActiveItems(i),t&&this.passedElement.triggerEvent("addItem",this._getChoiceForOutput(e))},e.prototype._removeItem=function(e){e.id&&(this._store.dispatch(function(e){return{type:"REMOVE_ITEM",item:e}}(e)),this.passedElement.triggerEvent("removeItem",this._getChoiceForOutput(e)))},e.prototype._addChoice=function(e,t){if(void 0===t&&(t=!0),0!==e.id)throw new TypeError("Can not re-add a choice which has already been added");var i=e;this._lastAddedChoiceId++,i.id=this._lastAddedChoiceId,i.elementId="".concat(this._baseId,"-").concat(this._idNames.itemChoice,"-").concat(i.id),this.config.prependValue&&(i.value=this.config.prependValue+i.value),this.config.appendValue&&(i.value+=this.config.appendValue.toString()),(this.config.prependValue||this.config.appendValue)&&i.element&&(i.element.value=i.value),this._store.dispatch(function(e){return{type:"ADD_CHOICE",choice:e}}(e)),e.selected&&this._addItem(e,t)},e.prototype._addGroup=function(e,t){var i=this;if(void 0===t&&(t=!0),0!==e.id)throw new TypeError("Can not re-add a group which has already been added");if(this._store.dispatch(function(e){return{type:"ADD_GROUP",group:e}}(e)),e.choices){var n=e;this._lastAddedGroupId++,n.id=this._lastAddedGroupId;var s=e.id,o=e.choices;n.choices=[],o.forEach((function(n){var o=n;o.groupId=s,e.disabled&&(o.disabled=!0),i._addChoice(o,t)}))}},e.prototype._getTemplate=function(e){for(var t,i=[],s=1;sSelect multiple inputs
+
+
+ Disabled via fieldset
+
+ Choice 1
+ Choice 2
+ Choice 3
+
+
+
+
Disabled via attribute
Select multiple inputs
addItems: false,
});
+ new Choices('#choices-disabled-via-fieldset', {
+ allowHTML: true,
+ });
+
new Choices('#choices-disabled-via-attr', {
allowHTML: true,
});
diff --git a/public/test/select-one/index.html b/public/test/select-one/index.html
index d52338f9d..80d1845b3 100644
--- a/public/test/select-one/index.html
+++ b/public/test/select-one/index.html
@@ -121,6 +121,21 @@ Select one inputs
+
+
+ Disabled via fieldset
+
+ Choice 1
+ Choice 2
+ Choice 3
+
+
+
+
Disabled via attribute
Select one inputs
addItems: false,
});
+ new Choices('#choices-disabled-via-fieldset', {
+ allowHTML: true,
+ });
+
new Choices('#choices-disabled-via-attr', {
allowHTML: true,
});
diff --git a/public/test/text/index.html b/public/test/text/index.html
index c3b272e16..110163ac2 100644
--- a/public/test/text/index.html
+++ b/public/test/text/index.html
@@ -119,6 +119,17 @@ Text inputs
/>
+
+ Disabled via fieldset
+
+
+
+
+
Disabled via attribute
Text inputs
addItems: false,
});
+ new Choices('#choices-disabled-via-fieldset', {
+ allowHTML: true,
+ });
+
new Choices('#choices-disabled-via-attr', {
allowHTML: true,
});
diff --git a/src/scripts/choices.ts b/src/scripts/choices.ts
index 115263bdd..649f1297c 100644
--- a/src/scripts/choices.ts
+++ b/src/scripts/choices.ts
@@ -388,8 +388,12 @@ class Choices implements ChoicesInterface {
this._addEventListeners();
const shouldDisable =
- !this.config.addItems ||
- this.passedElement.element.hasAttribute('disabled');
+ (this._isTextElement && !this.config.addItems) ||
+ (this._isSelectElement &&
+ !this.config.addChoices &&
+ this._store.choices.length === 0) ||
+ this.passedElement.element.hasAttribute('disabled') ||
+ !!this.passedElement.element.closest('fieldset:disabled');
if (shouldDisable) {
this.disable();