import PropertySelect from '../model/PropertySelect'; import PropertyView from './PropertyView'; export default class PropertySelectView extends PropertyView { templateInput() { const { pfx, ppfx } = this; return `
`; } constructor(o: any) { super(o); this.listenTo(this.model, 'change:options', this.updateOptions); } updateOptions() { delete this.input; this.onRender(); } onRender() { const { pfx } = this; const model = this.model as PropertySelect; const options = model.getOptions(); if (!this.input) { const optionsRes: string[] = []; options.forEach(option => { const id = model.getOptionId(option); const name = model.getOptionLabel(id); const style = option.style ? option.style.replace(/"/g, '"') : ''; const styleAttr = style ? `style="${style}"` : ''; const value = id.replace(/"/g, '"'); optionsRes.push(``); }); const inputH = this.el.querySelector(`#${pfx}input-holder`)!; inputH.innerHTML = ``; this.input = inputH.firstChild as HTMLInputElement; } } __setValueInput(value: string) { const model = this.model as PropertySelect; const input = this.getInputEl(); const firstOpt = model.getOptions()[0]; const firstId = firstOpt ? model.getOptionId(firstOpt) : ''; input && (input.value = value || firstId); } }