diff --git a/client/core/src/textfield/textfield.html b/client/core/src/textfield/textfield.html
index df899f2d0..6717fe21f 100644
--- a/client/core/src/textfield/textfield.html
+++ b/client/core/src/textfield/textfield.html
@@ -1,18 +1,20 @@
-
-
diff --git a/client/core/src/textfield/textfield.js b/client/core/src/textfield/textfield.js
index b137f2df8..a6859bce8 100644
--- a/client/core/src/textfield/textfield.js
+++ b/client/core/src/textfield/textfield.js
@@ -1,16 +1,20 @@
-import {module} from '../module';
-
+import { module } from '../module';
+import Component from '../lib/component';
// import * as resolveFactory from '../lib/resolveDefaultComponents';
// import * as normalizerFactory from '../lib/inputAttrsNormalizer';
import './style.scss';
// import './textfield.mdl';
-export default class TextfieldController {
+export default class TextfieldController extends Component {
constructor($element, $scope, $attrs) {
+ super($element);
this.$scope = $scope;
this.$attrs = $attrs;
- let input = this.input = this.$element.querySelector('input');
+ this.$element = $element[0];
+
+ let input = this.input = $element[0].querySelector('input');
+
input.addEventListener('input',
() => this.checkValue());
input.addEventListener('focus',
@@ -27,7 +31,17 @@ export default class TextfieldController {
let div = this.$element.firstChild;
componentHandler.upgradeElement(div);
- Object.assign(this, $attrs);
+ this._value = null;
+
+ this.type = this.$attrs.type || 'text';
+ }
+
+ get value() {
+ return this._value;
+ }
+
+ set value(value) {
+ this._value = (value === undefined || value === '') ? null : value;
}
$onInit() {
@@ -37,9 +51,10 @@ export default class TextfieldController {
this.$scope.$watch(this.$attrs.model,
() => mdlTextField.updateClasses_());
- let $input = angular.$element(this.input);
- $input.controller('ng-model').$parsers.push(value => value === '' ? null : value);
+ /* let $input = angular.element(this.input);
+ $input.controller('ng-model').$parsers.push(value => value === '' ? null : value);*/
}
+
onClearClick() {
this.input.value = null;
this.checkValue();
@@ -48,23 +63,21 @@ export default class TextfieldController {
event.initEvent('change', false, true);
this.input.dispatchEvent(event);
}
+
checkValue() {
this.showClear(this.input.value);
}
+
showClear(show) {
- show = show && document.activeElement === this.input;
+ show = (show && document.activeElement === this.input);
let clearButton = this.$element.querySelector('button');
clearButton.style.visibility = show ? 'visible' : 'hidden';
}
- /**
- * Selects the textfield.
- */
+
select() {
this.input.select();
}
- /**
- * Puts the focus on the textfield.
- */
+
focus() {
this.input.focus();
}
@@ -73,5 +86,8 @@ TextfieldController.$inject = ['$element', '$scope', '$attrs'];
module.component('vnTextfield', {
template: require('./textfield.html'),
- controller: TextfieldController
-});
+ controller: TextfieldController,
+ bindings: {
+ value: '=model'
+ }
+});
\ No newline at end of file