Current section

Files

Jump to
live_select priv static live_select.min.js
Raw

priv/static/live_select.min.js

export default{LiveSelect:{attachDomEventHandlers(){this.el.querySelector("input[type=text]").onkeydown=t=>{t.code==="Enter"&&t.preventDefault(),this.pushEventTo(this.el,"keydown",{key:t.code})}},setInputValue(t){this.el.querySelector("input[type=text]").value=t},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),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()}}};