refactoring textfield finished
This commit is contained in:
parent
cccc0ade2b
commit
2fd58af254
|
@ -11,15 +11,15 @@
|
||||||
<vn-vertical pad-large>
|
<vn-vertical pad-large>
|
||||||
<vn-title>Create client</vn-title>
|
<vn-title>Create client</vn-title>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-textfield vn-one label="Name" model="$ctrl.client.name" vn-focus></vn-textfield>
|
<vn-textfield vn-one label="Name" field="$ctrl.client.name" vn-focus></vn-textfield>
|
||||||
<vn-textfield vn-one label="Tax number" model="$ctrl.client.fi"></vn-textfield>
|
<vn-textfield vn-one label="Tax number" field="$ctrl.client.fi"></vn-textfield>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-textfield vn-one label="Business name" model="$ctrl.client.socialName"></vn-textfield>
|
<vn-textfield vn-one label="Business name" field="$ctrl.client.socialName"></vn-textfield>
|
||||||
<vn-textfield vn-one label="User name" model="$ctrl.client.userName"></vn-textfield>
|
<vn-textfield vn-one label="User name" field="$ctrl.client.userName"></vn-textfield>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-textfield vn-one label="Email" model="$ctrl.client.email" ></vn-textfield>
|
<vn-textfield vn-one label="Email" field="$ctrl.client.email" ></vn-textfield>
|
||||||
<vn-one></vn-one>
|
<vn-one></vn-one>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
</vn-vertical>
|
</vn-vertical>
|
||||||
|
|
|
@ -39,6 +39,7 @@ export function directive(interpolate, compile, $window) {
|
||||||
let errorMsg;
|
let errorMsg;
|
||||||
let errorShown = false;
|
let errorShown = false;
|
||||||
|
|
||||||
|
input.$options.$$options.allowInvalid = true;
|
||||||
input.$validators.entity = function(value) {
|
input.$validators.entity = function(value) {
|
||||||
try {
|
try {
|
||||||
validateAll(value, validations);
|
validateAll(value, validations);
|
||||||
|
|
|
@ -29,6 +29,7 @@ export class InputAttrsNormalizer {
|
||||||
|
|
||||||
if (attrs.focus !== undefined)
|
if (attrs.focus !== undefined)
|
||||||
attrs.focus = 'vn-focus';
|
attrs.focus = 'vn-focus';
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.service(NAME, InputAttrsNormalizer);
|
module.service(NAME, InputAttrsNormalizer);
|
||||||
|
|
|
@ -4,7 +4,6 @@ vn-textfield {
|
||||||
top: 0px;
|
top: 0px;
|
||||||
right: -6px;
|
right: -6px;
|
||||||
margin: 22px 0px;
|
margin: 22px 0px;
|
||||||
visibility: hidden;
|
|
||||||
background-color: white;
|
background-color: white;
|
||||||
}
|
}
|
||||||
.material-icons {
|
.material-icons {
|
||||||
|
|
|
@ -5,8 +5,16 @@
|
||||||
name="{{$ctrl.name}}"
|
name="{{$ctrl.name}}"
|
||||||
ng-model="$ctrl.value"
|
ng-model="$ctrl.value"
|
||||||
vn-validation="{{$ctrl.rule}}"
|
vn-validation="{{$ctrl.rule}}"
|
||||||
ng-disabled="$ctrl.disable"
|
ng-disabled="$ctrl.disabled"
|
||||||
/>
|
/>
|
||||||
|
<button
|
||||||
<label class="mdl-textfield__label">{{$ctrl.label | translate}}</label>
|
type="button"
|
||||||
|
class="mdl-chip__action"
|
||||||
|
tabindex="-1"
|
||||||
|
translate-attr="{title: 'Clear'}"
|
||||||
|
ng-show="$ctrl.showActions"
|
||||||
|
>
|
||||||
|
<i class="material-icons" ng-click="$ctrl.clear()">clear</i>
|
||||||
|
</button>
|
||||||
|
<label class="mdl-textfield__label" translate>{{$ctrl.label}}</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
import { module } from '../module';
|
import { module } from '../module';
|
||||||
import Component from '../lib/component';
|
import Component from '../lib/component';
|
||||||
// import * as resolveFactory from '../lib/resolveDefaultComponents';
|
import * as normalizerFactory from '../lib/inputAttrsNormalizer';
|
||||||
// import * as normalizerFactory from '../lib/inputAttrsNormalizer';
|
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
// import './textfield.mdl';
|
|
||||||
|
|
||||||
export default class TextfieldController extends Component {
|
export default class TextfieldController extends Component {
|
||||||
constructor($element, $scope, $attrs) {
|
constructor($element, $scope, $attrs, normalizer) {
|
||||||
super($element);
|
super($element);
|
||||||
|
|
||||||
|
normalizer.normalize($attrs);
|
||||||
|
|
||||||
this.$scope = $scope;
|
this.$scope = $scope;
|
||||||
this.$attrs = $attrs;
|
this.$attrs = $attrs;
|
||||||
this.$element = $element;
|
this.$element = $element;
|
||||||
|
|
||||||
this._value = null;
|
this._value = null;
|
||||||
|
|
||||||
this.type = this.$attrs.type || 'text';
|
this.type = this.$attrs.type || 'text';
|
||||||
this.rule = this.$attrs.rule || null;
|
this.showActions = false;
|
||||||
|
this.input = $element[0].querySelector('input');
|
||||||
|
|
||||||
componentHandler.upgradeElement($element[0].firstChild);
|
componentHandler.upgradeElement($element[0].firstChild);
|
||||||
}
|
}
|
||||||
|
@ -27,44 +27,33 @@ export default class TextfieldController extends Component {
|
||||||
|
|
||||||
set value(value) {
|
set value(value) {
|
||||||
this._value = (value === undefined || value === '') ? null : value;
|
this._value = (value === undefined || value === '') ? null : value;
|
||||||
|
this.input.value = this._value;
|
||||||
|
this.showActions = this._value !== null;
|
||||||
|
this.mdlUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
onClearClick() {
|
mdlUpdate() {
|
||||||
this.input.value = null;
|
let mdlField = this.$element[0].firstChild.MaterialTextfield;
|
||||||
this.checkValue();
|
if (mdlField)
|
||||||
|
mdlField.updateClasses_();
|
||||||
let event = this.document.createEvent('HTMLEvents');
|
|
||||||
event.initEvent('change', false, true);
|
|
||||||
this.input.dispatchEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
checkValue() {
|
clear() {
|
||||||
this.showClear(this.input.value);
|
this.value = null;
|
||||||
}
|
|
||||||
|
|
||||||
showClear(show) {
|
|
||||||
show = (show && document.activeElement === this.input);
|
|
||||||
let clearButton = this.$element.querySelector('button');
|
|
||||||
clearButton.style.visibility = show ? 'visible' : 'hidden';
|
|
||||||
}
|
|
||||||
|
|
||||||
select() {
|
|
||||||
this.input.select();
|
|
||||||
}
|
|
||||||
|
|
||||||
focus() {
|
|
||||||
this.input.focus();
|
this.input.focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TextfieldController.$inject = ['$element', '$scope', '$attrs'];
|
TextfieldController.$inject = ['$element', '$scope', '$attrs', normalizerFactory.NAME];
|
||||||
|
|
||||||
module.component('vnTextfield', {
|
module.component('vnTextfield', {
|
||||||
template: require('./textfield.html'),
|
template: require('./textfield.html'),
|
||||||
controller: TextfieldController,
|
controller: TextfieldController,
|
||||||
bindings: {
|
bindings: {
|
||||||
value: '=model',
|
value: '=model',
|
||||||
label: '@',
|
label: '@?',
|
||||||
name: '@',
|
name: '@?',
|
||||||
disable: '<'
|
disabled: '<?',
|
||||||
|
rule: '@?',
|
||||||
|
type: '@?'
|
||||||
}
|
}
|
||||||
});
|
});
|
Loading…
Reference in New Issue