Current section

Files

Jump to
live_select priv static live_select.min.js
Raw

priv/static/live_select.min.js

export default{LiveSelect:{textInput(){return this.el.querySelector("input[type=text]")},attachDomEventHandlers(){this.textInput().onkeydown=t=>{t.code==="Enter"&&t.preventDefault(),this.pushEventTo(this.el,"keydown",{key:t.code})},this.el.querySelector("ul").onmousedown=t=>{t.target.dataset.idx&&(this.textInput().blur(),this.pushEventTo(this.el,"option_click",{idx:t.target.dataset.idx}))}},setInputValue(t,e){this.textInput().value=t,e&&this.textInput().focus()},inputEvent(t,e){const n=e==="single"?"input.hidden":t.length===0?"input[name=live_select_empty_selection]":"input[type=hidden]";this.el.querySelector(n).dispatchEvent(new Event("input",{bubbles:!0}))},mounted(){this.handleEvent("reset",({id:t})=>{this.el.id===t&&(this.setInputValue(null,!0),this.inputEvent([],"single"))}),this.handleEvent("select",({id:t,selection:e,mode:n})=>{if(this.el.id===t)if(n==="single"){const[{label:i}]=e;this.setInputValue(i),this.inputEvent(e,n)}else this.setInputValue(null),this.inputEvent(e,n)}),this.attachDomEventHandlers()},updated(){this.attachDomEventHandlers()}}};