2017-09-12 10:45:29 +00:00
|
|
|
import { module } from '../module';
|
|
|
|
import Component from '../lib/component';
|
2017-09-13 07:45:42 +00:00
|
|
|
import * as normalizerFactory from '../lib/inputAttrsNormalizer';
|
2017-04-28 13:04:29 +00:00
|
|
|
import './style.scss';
|
|
|
|
|
2017-09-12 10:45:29 +00:00
|
|
|
export default class TextfieldController extends Component {
|
2017-09-13 07:45:42 +00:00
|
|
|
constructor($element, $scope, $attrs, normalizer) {
|
2017-09-12 10:45:29 +00:00
|
|
|
super($element);
|
2017-04-28 13:04:29 +00:00
|
|
|
|
2017-09-13 07:45:42 +00:00
|
|
|
normalizer.normalize($attrs);
|
|
|
|
|
2017-09-12 09:44:56 +00:00
|
|
|
this.$scope = $scope;
|
|
|
|
this.$attrs = $attrs;
|
2017-09-12 13:02:14 +00:00
|
|
|
this.$element = $element;
|
2017-09-07 17:35:17 +00:00
|
|
|
|
2017-09-12 10:45:29 +00:00
|
|
|
this._value = null;
|
|
|
|
this.type = this.$attrs.type || 'text';
|
2017-09-13 07:45:42 +00:00
|
|
|
this.showActions = false;
|
|
|
|
this.input = $element[0].querySelector('input');
|
2017-09-13 08:59:34 +00:00
|
|
|
this.focus = false;
|
|
|
|
this.hasInfo = Boolean(this.$attrs.info);
|
|
|
|
this.info = this.$attrs.info || null;
|
2017-09-13 07:45:42 +00:00
|
|
|
|
2017-09-12 13:02:14 +00:00
|
|
|
componentHandler.upgradeElement($element[0].firstChild);
|
2017-09-12 10:45:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get value() {
|
|
|
|
return this._value;
|
|
|
|
}
|
|
|
|
|
|
|
|
set value(value) {
|
|
|
|
this._value = (value === undefined || value === '') ? null : value;
|
2017-09-13 07:45:42 +00:00
|
|
|
this.input.value = this._value;
|
2017-09-13 08:59:34 +00:00
|
|
|
this.hasValue = Boolean(this._value);
|
2017-09-13 07:45:42 +00:00
|
|
|
this.mdlUpdate();
|
2017-04-28 13:04:29 +00:00
|
|
|
}
|
2017-09-12 09:44:56 +00:00
|
|
|
|
2017-09-13 07:45:42 +00:00
|
|
|
mdlUpdate() {
|
|
|
|
let mdlField = this.$element[0].firstChild.MaterialTextfield;
|
|
|
|
if (mdlField)
|
|
|
|
mdlField.updateClasses_();
|
2017-05-18 15:35:07 +00:00
|
|
|
}
|
2017-09-12 10:45:29 +00:00
|
|
|
|
2017-09-13 07:45:42 +00:00
|
|
|
clear() {
|
|
|
|
this.value = null;
|
2017-05-18 15:35:07 +00:00
|
|
|
this.input.focus();
|
|
|
|
}
|
2017-04-28 13:04:29 +00:00
|
|
|
}
|
2017-09-13 07:45:42 +00:00
|
|
|
TextfieldController.$inject = ['$element', '$scope', '$attrs', normalizerFactory.NAME];
|
2017-04-28 13:04:29 +00:00
|
|
|
|
2017-09-12 09:44:56 +00:00
|
|
|
module.component('vnTextfield', {
|
|
|
|
template: require('./textfield.html'),
|
2017-09-12 10:45:29 +00:00
|
|
|
controller: TextfieldController,
|
|
|
|
bindings: {
|
2017-09-12 13:02:14 +00:00
|
|
|
value: '=model',
|
2017-09-13 07:45:42 +00:00
|
|
|
label: '@?',
|
|
|
|
name: '@?',
|
|
|
|
disabled: '<?',
|
|
|
|
rule: '@?',
|
|
|
|
type: '@?'
|
2017-09-12 10:45:29 +00:00
|
|
|
}
|
2017-09-13 07:45:42 +00:00
|
|
|
});
|