validator.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = Object.setPrototypeOf ||
  4. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  6. return function (d, b) {
  7. extendStatics(d, b);
  8. function __() { this.constructor = d; }
  9. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10. };
  11. })();
  12. /*!
  13. * devextreme-angular
  14. * Version: 19.1.16
  15. * Build date: Tue Oct 18 2022
  16. *
  17. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  18. *
  19. * This software may be modified and distributed under the terms
  20. * of the MIT license. See the LICENSE file in the root of the project for details.
  21. *
  22. * https://github.com/DevExpress/devextreme-angular
  23. */
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. var platform_browser_1 = require("@angular/platform-browser");
  26. var platform_browser_2 = require("@angular/platform-browser");
  27. var core_1 = require("@angular/core");
  28. var validator_1 = require("devextreme/ui/validator");
  29. var component_1 = require("../core/component");
  30. var template_host_1 = require("../core/template-host");
  31. var integration_1 = require("../core/integration");
  32. var template_1 = require("../core/template");
  33. var nested_option_1 = require("../core/nested-option");
  34. var watcher_helper_1 = require("../core/watcher-helper");
  35. var iterable_differ_helper_1 = require("../core/iterable-differ-helper");
  36. var adapter_1 = require("./nested/adapter");
  37. var validation_rule_dxi_1 = require("./nested/validation-rule-dxi");
  38. var validation_rule_dxi_2 = require("./nested/validation-rule-dxi");
  39. /**
  40. * A widget that is used to validate the associated DevExtreme editors against the defined validation rules.
  41. */
  42. var DxValidatorComponent = (function (_super) {
  43. __extends(DxValidatorComponent, _super);
  44. function DxValidatorComponent(elementRef, ngZone, templateHost, _watcherHelper, _idh, parentOptionHost, optionHost, transferState, platformId) {
  45. var _this = _super.call(this, elementRef, ngZone, templateHost, _watcherHelper, transferState, platformId) || this;
  46. _this._watcherHelper = _watcherHelper;
  47. _this._idh = _idh;
  48. _this._createEventEmitters([
  49. { subscribe: 'disposing', emit: 'onDisposing' },
  50. { subscribe: 'initialized', emit: 'onInitialized' },
  51. { subscribe: 'optionChanged', emit: 'onOptionChanged' },
  52. { subscribe: 'validated', emit: 'onValidated' },
  53. { emit: 'adapterChange' },
  54. { emit: 'elementAttrChange' },
  55. { emit: 'heightChange' },
  56. { emit: 'nameChange' },
  57. { emit: 'validationGroupChange' },
  58. { emit: 'validationRulesChange' },
  59. { emit: 'widthChange' }
  60. ]);
  61. _this.parentElement = _this.getParentElement(parentOptionHost);
  62. _this._idh.setHost(_this);
  63. optionHost.setHost(_this);
  64. return _this;
  65. }
  66. Object.defineProperty(DxValidatorComponent.prototype, "adapter", {
  67. get: /**
  68. * An object that specifies what and when to validate, and how to apply the validation result.
  69. */
  70. function () {
  71. return this._getOption('adapter');
  72. },
  73. set: function (value) {
  74. this._setOption('adapter', value);
  75. },
  76. enumerable: true,
  77. configurable: true
  78. });
  79. Object.defineProperty(DxValidatorComponent.prototype, "elementAttr", {
  80. get: /**
  81. * Specifies the attributes to be attached to the widget's root element.
  82. */
  83. function () {
  84. return this._getOption('elementAttr');
  85. },
  86. set: function (value) {
  87. this._setOption('elementAttr', value);
  88. },
  89. enumerable: true,
  90. configurable: true
  91. });
  92. Object.defineProperty(DxValidatorComponent.prototype, "height", {
  93. get: /**
  94. * Specifies the widget's height.
  95. */
  96. function () {
  97. return this._getOption('height');
  98. },
  99. set: function (value) {
  100. this._setOption('height', value);
  101. },
  102. enumerable: true,
  103. configurable: true
  104. });
  105. Object.defineProperty(DxValidatorComponent.prototype, "name", {
  106. get: /**
  107. * Specifies the editor name to be used in the validation default messages.
  108. */
  109. function () {
  110. return this._getOption('name');
  111. },
  112. set: function (value) {
  113. this._setOption('name', value);
  114. },
  115. enumerable: true,
  116. configurable: true
  117. });
  118. Object.defineProperty(DxValidatorComponent.prototype, "validationGroup", {
  119. get: /**
  120. * Specifies the validation group the editor will be related to.
  121. */
  122. function () {
  123. return this._getOption('validationGroup');
  124. },
  125. set: function (value) {
  126. this._setOption('validationGroup', value);
  127. },
  128. enumerable: true,
  129. configurable: true
  130. });
  131. Object.defineProperty(DxValidatorComponent.prototype, "validationRules", {
  132. get: /**
  133. * An array of validation rules to be checked for the editor with which the dxValidator object is associated.
  134. */
  135. function () {
  136. return this._getOption('validationRules');
  137. },
  138. set: function (value) {
  139. this._setOption('validationRules', value);
  140. },
  141. enumerable: true,
  142. configurable: true
  143. });
  144. Object.defineProperty(DxValidatorComponent.prototype, "width", {
  145. get: /**
  146. * Specifies the widget's width.
  147. */
  148. function () {
  149. return this._getOption('width');
  150. },
  151. set: function (value) {
  152. this._setOption('width', value);
  153. },
  154. enumerable: true,
  155. configurable: true
  156. });
  157. Object.defineProperty(DxValidatorComponent.prototype, "validationRulesChildren", {
  158. get: function () {
  159. return this._getOption('validationRules');
  160. },
  161. set: function (value) {
  162. this.setChildren('validationRules', value);
  163. },
  164. enumerable: true,
  165. configurable: true
  166. });
  167. DxValidatorComponent.prototype._createInstance = function (element, options) {
  168. if (this.parentElement) {
  169. return new validator_1.default(this.parentElement, options);
  170. }
  171. return new validator_1.default(element, options);
  172. };
  173. DxValidatorComponent.prototype.getParentElement = function (host) {
  174. if (host) {
  175. var parentHost = host.getHost();
  176. return parentHost.element.nativeElement;
  177. }
  178. return;
  179. };
  180. DxValidatorComponent.prototype.ngOnDestroy = function () {
  181. this._destroyWidget();
  182. };
  183. DxValidatorComponent.prototype.ngOnChanges = function (changes) {
  184. _super.prototype.ngOnChanges.call(this, changes);
  185. this.setupChanges('validationRules', changes);
  186. };
  187. DxValidatorComponent.prototype.setupChanges = function (prop, changes) {
  188. if (!(prop in this._optionsToUpdate)) {
  189. this._idh.setup(prop, changes);
  190. }
  191. };
  192. DxValidatorComponent.prototype.ngDoCheck = function () {
  193. this._idh.doCheck('validationRules');
  194. this._watcherHelper.checkWatchers();
  195. _super.prototype.ngDoCheck.call(this);
  196. _super.prototype.clearChangedOptions.call(this);
  197. };
  198. DxValidatorComponent.prototype._setOption = function (name, value) {
  199. var isSetup = this._idh.setupSingle(name, value);
  200. var isChanged = this._idh.getChanges(name, value) !== null;
  201. if (isSetup || isChanged) {
  202. _super.prototype._setOption.call(this, name, value);
  203. }
  204. };
  205. DxValidatorComponent.decorators = [
  206. { type: core_1.Component, args: [{
  207. selector: 'dx-validator',
  208. template: '',
  209. providers: [
  210. template_host_1.DxTemplateHost,
  211. watcher_helper_1.WatcherHelper,
  212. nested_option_1.NestedOptionHost,
  213. iterable_differ_helper_1.IterableDifferHelper
  214. ]
  215. },] },
  216. ];
  217. /** @nocollapse */
  218. DxValidatorComponent.ctorParameters = function () { return [
  219. { type: core_1.ElementRef, },
  220. { type: core_1.NgZone, },
  221. { type: template_host_1.DxTemplateHost, },
  222. { type: watcher_helper_1.WatcherHelper, },
  223. { type: iterable_differ_helper_1.IterableDifferHelper, },
  224. { type: nested_option_1.NestedOptionHost, decorators: [{ type: core_1.SkipSelf }, { type: core_1.Optional }, { type: core_1.Host },] },
  225. { type: nested_option_1.NestedOptionHost, },
  226. { type: platform_browser_2.TransferState, },
  227. { type: undefined, decorators: [{ type: core_1.Inject, args: [core_1.PLATFORM_ID,] },] },
  228. ]; };
  229. DxValidatorComponent.propDecorators = {
  230. "adapter": [{ type: core_1.Input },],
  231. "elementAttr": [{ type: core_1.Input },],
  232. "height": [{ type: core_1.Input },],
  233. "name": [{ type: core_1.Input },],
  234. "validationGroup": [{ type: core_1.Input },],
  235. "validationRules": [{ type: core_1.Input },],
  236. "width": [{ type: core_1.Input },],
  237. "onDisposing": [{ type: core_1.Output },],
  238. "onInitialized": [{ type: core_1.Output },],
  239. "onOptionChanged": [{ type: core_1.Output },],
  240. "onValidated": [{ type: core_1.Output },],
  241. "adapterChange": [{ type: core_1.Output },],
  242. "elementAttrChange": [{ type: core_1.Output },],
  243. "heightChange": [{ type: core_1.Output },],
  244. "nameChange": [{ type: core_1.Output },],
  245. "validationGroupChange": [{ type: core_1.Output },],
  246. "validationRulesChange": [{ type: core_1.Output },],
  247. "widthChange": [{ type: core_1.Output },],
  248. "validationRulesChildren": [{ type: core_1.ContentChildren, args: [validation_rule_dxi_2.DxiValidationRuleComponent,] },],
  249. };
  250. return DxValidatorComponent;
  251. }(component_1.DxComponentExtension));
  252. exports.DxValidatorComponent = DxValidatorComponent;
  253. var DxValidatorModule = (function () {
  254. function DxValidatorModule() {
  255. }
  256. DxValidatorModule.decorators = [
  257. { type: core_1.NgModule, args: [{
  258. imports: [
  259. adapter_1.DxoAdapterModule,
  260. validation_rule_dxi_1.DxiValidationRuleModule,
  261. integration_1.DxIntegrationModule,
  262. template_1.DxTemplateModule,
  263. platform_browser_1.BrowserTransferStateModule
  264. ],
  265. declarations: [
  266. DxValidatorComponent
  267. ],
  268. exports: [
  269. DxValidatorComponent,
  270. adapter_1.DxoAdapterModule,
  271. validation_rule_dxi_1.DxiValidationRuleModule,
  272. template_1.DxTemplateModule
  273. ]
  274. },] },
  275. ];
  276. return DxValidatorModule;
  277. }());
  278. exports.DxValidatorModule = DxValidatorModule;
  279. //# sourceMappingURL=validator.js.map