/*! * devextreme-angular-test * Version: 17.2.8 * Build date: Mon Feb 05 2018 * * Copyright (c) 2012 - 2018 Developer Express Inc. ALL RIGHTS RESERVED * * This software may be modified and distributed under the terms * of the MIT license. See the LICENSE file in the root of the project for details. * * https://github.com/DevExpress/devextreme-angular */ import { Component, NgModule, ElementRef, NgZone, Input, Output, OnDestroy, Injector, EventEmitter, OnChanges, DoCheck, SimpleChanges, ContentChildren, QueryList } from '@angular/core'; import DevExpress from 'devextreme/bundles/dx.all'; import DxValidator from 'devextreme/ui/validator'; import { DxComponentExtension } from '../core/component'; import { DxTemplateHost } from '../core/template-host'; import { DxTemplateModule } from '../core/template'; import { EventsRegistrator } from '../core/events-strategy'; import { NestedOptionHost } from '../core/nested-option'; import { WatcherHelper } from '../core/watcher-helper'; import { IterableDifferHelper } from '../core/iterable-differ-helper'; import { DxoAdapterModule } from './nested/adapter'; import { DxiValidationRuleModule } from './nested/validation-rule-dxi'; import { DxiValidationRuleComponent } from './nested/validation-rule-dxi'; /** * A widget that is used to validate the associated DevExtreme editors against the defined validation rules. */ @Component({ selector: 'dx-validator', template: '', providers: [ DxTemplateHost, WatcherHelper, NestedOptionHost, IterableDifferHelper ] }) export class DxValidatorComponent extends DxComponentExtension implements OnDestroy, OnChanges, DoCheck { instance: DxValidator; /** * An object that specifies what and when to validate, and how to apply the validation result. */ @Input() get adapter(): any { return this._getOption('adapter'); } set adapter(value: any) { this._setOption('adapter', value); } /** * Specifies the attributes to be attached to the widget's root element. */ @Input() get elementAttr(): any { return this._getOption('elementAttr'); } set elementAttr(value: any) { this._setOption('elementAttr', value); } /** * Specifies the widget's height. */ @Input() get height(): number| Function| string { return this._getOption('height'); } set height(value: number| Function| string) { this._setOption('height', value); } /** * Specifies the editor name to be used in the validation default messages. */ @Input() get name(): string { return this._getOption('name'); } set name(value: string) { this._setOption('name', value); } /** * Specifies the validation group the editor will be related to. */ @Input() get validationGroup(): string { return this._getOption('validationGroup'); } set validationGroup(value: string) { this._setOption('validationGroup', value); } /** * An array of validation rules to be checked for the editor with which the dxValidator object is associated. */ @Input() get validationRules(): Array { return this._getOption('validationRules'); } set validationRules(value: Array) { this._setOption('validationRules', value); } /** * Specifies the widget's width. */ @Input() get width(): number| Function| string { return this._getOption('width'); } set width(value: number| Function| string) { this._setOption('width', value); } /** * A handler for the disposing event. Executed when the widget is removed from the DOM using the remove(), empty(), or html() jQuery methods only. */ @Output() onDisposing: EventEmitter; /** * A handler for the initialized event. Executed only once, after the widget is initialized. */ @Output() onInitialized: EventEmitter; /** * A handler for the optionChanged event. Executed after an option of the widget is changed. */ @Output() onOptionChanged: EventEmitter; /** * A handler for the validated event. */ @Output() onValidated: EventEmitter; /** * A handler for the adapterChange event. */ @Output() adapterChange: EventEmitter; /** * A handler for the elementAttrChange event. */ @Output() elementAttrChange: EventEmitter; /** * A handler for the heightChange event. */ @Output() heightChange: EventEmitter; /** * A handler for the nameChange event. */ @Output() nameChange: EventEmitter; /** * A handler for the validationGroupChange event. */ @Output() validationGroupChange: EventEmitter; /** * A handler for the validationRulesChange event. */ @Output() validationRulesChange: EventEmitter>; /** * A handler for the widthChange event. */ @Output() widthChange: EventEmitter; @ContentChildren(DxiValidationRuleComponent) get validationRulesChildren(): QueryList { return this._getOption('validationRules'); } set validationRulesChildren(value) { this.setChildren('validationRules', value); } constructor(elementRef: ElementRef, ngZone: NgZone, templateHost: DxTemplateHost, injector: Injector, private _watcherHelper: WatcherHelper, private _idh: IterableDifferHelper, optionHost: NestedOptionHost) { super(elementRef, ngZone, templateHost, _watcherHelper); injector.get(EventsRegistrator); this._createEventEmitters([ { subscribe: 'disposing', emit: 'onDisposing' }, { subscribe: 'initialized', emit: 'onInitialized' }, { subscribe: 'optionChanged', emit: 'onOptionChanged' }, { subscribe: 'validated', emit: 'onValidated' }, { emit: 'adapterChange' }, { emit: 'elementAttrChange' }, { emit: 'heightChange' }, { emit: 'nameChange' }, { emit: 'validationGroupChange' }, { emit: 'validationRulesChange' }, { emit: 'widthChange' } ]); this._idh.setHost(this); optionHost.setHost(this); } protected _createInstance(element, options) { return new DxValidator(element, options); } ngOnDestroy() { this._destroyWidget(); } ngOnChanges(changes: SimpleChanges) { super.ngOnChanges(changes); this.setupChanges('validationRules', changes); } setupChanges(prop: string, changes: SimpleChanges) { if (!(prop in this._optionsToUpdate)) { this._idh.setup(prop, changes); } } ngDoCheck() { this._idh.doCheck('validationRules'); this._watcherHelper.checkWatchers(); super.ngDoCheck(); } _setOption(name: string, value: any) { let isSetup = this._idh.setupSingle(name, value); let isChanged = this._idh.getChanges(name, value) !== null; if (isSetup || isChanged) { super._setOption(name, value); } } } @NgModule({ imports: [ DxoAdapterModule, DxiValidationRuleModule, DxTemplateModule ], declarations: [ DxValidatorComponent ], exports: [ DxValidatorComponent, DxoAdapterModule, DxiValidationRuleModule, DxTemplateModule ], providers: [EventsRegistrator] }) export class DxValidatorModule { }