2017-09-12 10:45:29 +00:00
|
|
|
import { module } from '../module';
|
|
|
|
import Component from '../lib/component';
|
2017-09-12 09:44:56 +00:00
|
|
|
// import * as resolveFactory from '../lib/resolveDefaultComponents';
|
|
|
|
// import * as normalizerFactory from '../lib/inputAttrsNormalizer';
|
2017-04-28 13:04:29 +00:00
|
|
|
import './style.scss';
|
2017-09-12 09:44:56 +00:00
|
|
|
// import './textfield.mdl';
|
2017-04-28 13:04:29 +00:00
|
|
|
|
2017-09-12 10:45:29 +00:00
|
|
|
export default class TextfieldController extends Component {
|
2017-04-28 13:04:29 +00:00
|
|
|
constructor($element, $scope, $attrs) {
|
2017-09-12 10:45:29 +00:00
|
|
|
super($element);
|
2017-04-28 13:04:29 +00:00
|
|
|
|
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-12 13:02:14 +00:00
|
|
|
this.rule = this.$attrs.rule || null;
|
|
|
|
|
|
|
|
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-04-28 13:04:29 +00:00
|
|
|
}
|
2017-09-12 09:44:56 +00:00
|
|
|
|
2017-04-28 13:04:29 +00:00
|
|
|
onClearClick() {
|
2017-09-07 17:35:17 +00:00
|
|
|
this.input.value = null;
|
2017-04-28 13:04:29 +00:00
|
|
|
this.checkValue();
|
|
|
|
|
|
|
|
let event = this.document.createEvent('HTMLEvents');
|
|
|
|
event.initEvent('change', false, true);
|
|
|
|
this.input.dispatchEvent(event);
|
|
|
|
}
|
2017-09-12 10:45:29 +00:00
|
|
|
|
2017-04-28 13:04:29 +00:00
|
|
|
checkValue() {
|
|
|
|
this.showClear(this.input.value);
|
|
|
|
}
|
2017-09-12 10:45:29 +00:00
|
|
|
|
2017-04-28 13:04:29 +00:00
|
|
|
showClear(show) {
|
2017-09-12 10:45:29 +00:00
|
|
|
show = (show && document.activeElement === this.input);
|
2017-09-12 09:44:56 +00:00
|
|
|
let clearButton = this.$element.querySelector('button');
|
2017-04-28 13:04:29 +00:00
|
|
|
clearButton.style.visibility = show ? 'visible' : 'hidden';
|
|
|
|
}
|
2017-09-12 10:45:29 +00:00
|
|
|
|
2017-05-18 15:35:07 +00:00
|
|
|
select() {
|
|
|
|
this.input.select();
|
|
|
|
}
|
2017-09-12 10:45:29 +00:00
|
|
|
|
2017-05-18 15:35:07 +00:00
|
|
|
focus() {
|
|
|
|
this.input.focus();
|
|
|
|
}
|
2017-04-28 13:04:29 +00:00
|
|
|
}
|
2017-09-12 09:44:56 +00:00
|
|
|
TextfieldController.$inject = ['$element', '$scope', '$attrs'];
|
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',
|
|
|
|
label: '@',
|
|
|
|
name: '@',
|
|
|
|
disable: '<'
|
2017-09-12 10:45:29 +00:00
|
|
|
}
|
|
|
|
});
|