import {module} from '../module'; import Component from '../lib/component'; import * as normalizerFactory from '../lib/inputAttrsNormalizer'; import './style.scss'; export default class TextfieldController extends Component { constructor($element, $scope, $attrs, normalizer) { super($element); normalizer.normalize($attrs); this.$scope = $scope; this.$attrs = $attrs; this.$element = $element; this._value = null; this.type = this.$attrs.type || 'text'; this.showActions = false; this.input = $element[0].querySelector('input'); this.focus = false; this.hasInfo = Boolean(this.$attrs.info); this.info = this.$attrs.info || null; componentHandler.upgradeElement($element[0].firstChild); } get value() { return this._value; } set value(value) { this._value = (value === undefined || value === '') ? null : value; this.input.value = this._value; this.hasValue = Boolean(this._value); this.mdlUpdate(); } mdlUpdate() { let mdlField = this.$element[0].firstChild.MaterialTextfield; if (mdlField) mdlField.updateClasses_(); } clear() { this.value = null; this.input.focus(); } } TextfieldController.$inject = ['$element', '$scope', '$attrs', normalizerFactory.NAME]; module.component('vnTextfield', { template: require('./textfield.html'), controller: TextfieldController, bindings: { value: '=model', label: '@?', name: '@?', disabled: '