import { isString, isUndefined } from 'underscore'; import { $ } from '../../common'; import TraitView from './TraitView'; export default class TraitSelectView extends TraitView { constructor(o = {}) { super(o); this.listenTo(this.model, 'change:options', this.rerender); } templateInput() { const { ppfx, clsField } = this; return `
`; } /** * Returns input element * @return {HTMLElement} * @private */ getInputEl() { if (!this.$input) { const { model, em } = this; const propName = model.get('name'); const opts = model.get('options') || []; const values: string[] = []; let input = ''; this.$input = $(input); const val = model.getTargetValue(); const valResult = values.indexOf(val) >= 0 ? val : model.get('default'); !isUndefined(valResult) && this.$input!.val(valResult); } return this.$input!.get(0); } }