@firestitch/form 9.7.7 → 12.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/app/components/form-dialog-actions/form-dialog-actions.component.d.ts +21 -18
  2. package/app/consts/error-messages.const.d.ts +19 -19
  3. package/app/directives/form/form.directive.d.ts +105 -102
  4. package/app/directives/form-dialog-close.directive.d.ts +12 -9
  5. package/app/directives/submit-button.directive.d.ts +31 -28
  6. package/app/directives/validators/compare.directive.d.ts +15 -12
  7. package/app/directives/validators/control.directive.d.ts +48 -45
  8. package/app/directives/validators/daterange.directive.d.ts +13 -10
  9. package/app/directives/validators/email.directive.d.ts +13 -10
  10. package/app/directives/validators/emails.directive.d.ts +13 -10
  11. package/app/directives/validators/function.directive.d.ts +14 -11
  12. package/app/directives/validators/greater.directive.d.ts +13 -10
  13. package/app/directives/validators/integer.directive.d.ts +13 -10
  14. package/app/directives/validators/lesser.directive.d.ts +13 -10
  15. package/app/directives/validators/max.directive.d.ts +13 -10
  16. package/app/directives/validators/maxlength.directive.d.ts +13 -10
  17. package/app/directives/validators/min.directive.d.ts +13 -10
  18. package/app/directives/validators/minlength.directive.d.ts +13 -10
  19. package/app/directives/validators/numeric.directive.d.ts +13 -10
  20. package/app/directives/validators/pattern.directive.d.ts +13 -10
  21. package/app/directives/validators/phone.directive.d.ts +13 -10
  22. package/app/directives/validators/required.directive.d.ts +16 -13
  23. package/app/directives/validators/url.directive.d.ts +14 -11
  24. package/app/directives/validators/validate.directive.d.ts +14 -11
  25. package/app/enums/confirm-result.d.ts +7 -7
  26. package/app/enums/form-status.d.ts +9 -9
  27. package/app/fs-form.module.d.ts +35 -4
  28. package/app/guards/form-deactivate.guard.d.ts +12 -9
  29. package/app/helpers/confirm-result-continue.d.ts +1 -1
  30. package/app/helpers/confirm-unsaved.d.ts +5 -5
  31. package/app/helpers/get-form-errors.d.ts +2 -2
  32. package/app/helpers/index.d.ts +2 -2
  33. package/app/helpers/is-enabled.d.ts +1 -1
  34. package/app/interfaces/async-validator.d.ts +14 -14
  35. package/app/interfaces/confirm-config.d.ts +7 -7
  36. package/app/interfaces/confirm-tab-group.d.ts +10 -10
  37. package/app/interfaces/form-deactivate.d.ts +4 -4
  38. package/app/interfaces/index.d.ts +4 -4
  39. package/app/interfaces/submit-event.d.ts +5 -5
  40. package/app/interfaces/submitted-event.d.ts +6 -6
  41. package/app/interfaces/validator.d.ts +13 -13
  42. package/app/providers/validate-messages.provider.d.ts +25 -25
  43. package/app/services/fsform.service.d.ts +10 -7
  44. package/app/validators/validators.d.ts +12 -12
  45. package/bundles/firestitch-form.umd.js +2588 -2459
  46. package/bundles/firestitch-form.umd.js.map +1 -1
  47. package/esm2015/app/components/form-dialog-actions/form-dialog-actions.component.js +86 -93
  48. package/esm2015/app/consts/error-messages.const.js +20 -20
  49. package/esm2015/app/directives/form/form.directive.js +619 -665
  50. package/esm2015/app/directives/form-dialog-close.directive.js +31 -33
  51. package/esm2015/app/directives/submit-button.directive.js +131 -138
  52. package/esm2015/app/directives/validators/compare.directive.js +49 -49
  53. package/esm2015/app/directives/validators/control.directive.js +257 -273
  54. package/esm2015/app/directives/validators/daterange.directive.js +41 -41
  55. package/esm2015/app/directives/validators/email.directive.js +41 -41
  56. package/esm2015/app/directives/validators/emails.directive.js +41 -41
  57. package/esm2015/app/directives/validators/function.directive.js +31 -31
  58. package/esm2015/app/directives/validators/greater.directive.js +40 -40
  59. package/esm2015/app/directives/validators/integer.directive.js +41 -41
  60. package/esm2015/app/directives/validators/lesser.directive.js +40 -40
  61. package/esm2015/app/directives/validators/max.directive.js +36 -36
  62. package/esm2015/app/directives/validators/maxlength.directive.js +35 -35
  63. package/esm2015/app/directives/validators/min.directive.js +36 -36
  64. package/esm2015/app/directives/validators/minlength.directive.js +35 -35
  65. package/esm2015/app/directives/validators/numeric.directive.js +41 -41
  66. package/esm2015/app/directives/validators/pattern.directive.js +35 -35
  67. package/esm2015/app/directives/validators/phone.directive.js +41 -41
  68. package/esm2015/app/directives/validators/required.directive.js +71 -73
  69. package/esm2015/app/directives/validators/url.directive.js +47 -49
  70. package/esm2015/app/directives/validators/validate.directive.js +33 -31
  71. package/esm2015/app/enums/confirm-result.js +9 -9
  72. package/esm2015/app/enums/form-status.js +11 -11
  73. package/esm2015/app/fs-form.module.js +165 -106
  74. package/esm2015/app/guards/form-deactivate.guard.js +40 -44
  75. package/esm2015/app/helpers/confirm-result-continue.js +5 -5
  76. package/esm2015/app/helpers/confirm-unsaved.js +70 -70
  77. package/esm2015/app/helpers/get-form-errors.js +25 -25
  78. package/esm2015/app/helpers/index.js +3 -3
  79. package/esm2015/app/helpers/is-enabled.js +4 -4
  80. package/esm2015/app/interfaces/async-validator.js +2 -1
  81. package/esm2015/app/interfaces/confirm-config.js +2 -1
  82. package/esm2015/app/interfaces/confirm-tab-group.js +2 -1
  83. package/esm2015/app/interfaces/form-deactivate.js +2 -1
  84. package/esm2015/app/interfaces/index.js +5 -1
  85. package/esm2015/app/interfaces/submit-event.js +2 -1
  86. package/esm2015/app/interfaces/submitted-event.js +2 -1
  87. package/esm2015/app/interfaces/validator.js +2 -1
  88. package/esm2015/app/providers/validate-messages.provider.js +11 -11
  89. package/esm2015/app/services/fsform.service.js +25 -26
  90. package/esm2015/app/validators/validators.js +97 -97
  91. package/esm2015/firestitch-form.js +5 -27
  92. package/esm2015/public_api.js +35 -14
  93. package/fesm2015/firestitch-form.js +2100 -2107
  94. package/fesm2015/firestitch-form.js.map +1 -1
  95. package/firestitch-form.d.ts +5 -26
  96. package/package.json +7 -8
  97. package/public_api.d.ts +33 -12
  98. package/styles.scss +4 -4
  99. package/bundles/firestitch-form.umd.min.js +0 -16
  100. package/bundles/firestitch-form.umd.min.js.map +0 -1
  101. package/esm5/app/components/form-dialog-actions/form-dialog-actions.component.js +0 -96
  102. package/esm5/app/consts/error-messages.const.js +0 -20
  103. package/esm5/app/directives/form/form.directive.js +0 -706
  104. package/esm5/app/directives/form-dialog-close.directive.js +0 -34
  105. package/esm5/app/directives/submit-button.directive.js +0 -144
  106. package/esm5/app/directives/validators/compare.directive.js +0 -60
  107. package/esm5/app/directives/validators/control.directive.js +0 -279
  108. package/esm5/app/directives/validators/daterange.directive.js +0 -50
  109. package/esm5/app/directives/validators/email.directive.js +0 -50
  110. package/esm5/app/directives/validators/emails.directive.js +0 -50
  111. package/esm5/app/directives/validators/function.directive.js +0 -36
  112. package/esm5/app/directives/validators/greater.directive.js +0 -49
  113. package/esm5/app/directives/validators/integer.directive.js +0 -50
  114. package/esm5/app/directives/validators/lesser.directive.js +0 -49
  115. package/esm5/app/directives/validators/max.directive.js +0 -45
  116. package/esm5/app/directives/validators/maxlength.directive.js +0 -44
  117. package/esm5/app/directives/validators/min.directive.js +0 -45
  118. package/esm5/app/directives/validators/minlength.directive.js +0 -44
  119. package/esm5/app/directives/validators/numeric.directive.js +0 -50
  120. package/esm5/app/directives/validators/pattern.directive.js +0 -44
  121. package/esm5/app/directives/validators/phone.directive.js +0 -50
  122. package/esm5/app/directives/validators/required.directive.js +0 -88
  123. package/esm5/app/directives/validators/url.directive.js +0 -56
  124. package/esm5/app/directives/validators/validate.directive.js +0 -36
  125. package/esm5/app/enums/confirm-result.js +0 -9
  126. package/esm5/app/enums/form-status.js +0 -11
  127. package/esm5/app/fs-form.module.js +0 -110
  128. package/esm5/app/guards/form-deactivate.guard.js +0 -45
  129. package/esm5/app/helpers/confirm-result-continue.js +0 -5
  130. package/esm5/app/helpers/confirm-unsaved.js +0 -70
  131. package/esm5/app/helpers/get-form-errors.js +0 -28
  132. package/esm5/app/helpers/index.js +0 -3
  133. package/esm5/app/helpers/is-enabled.js +0 -4
  134. package/esm5/app/interfaces/async-validator.js +0 -1
  135. package/esm5/app/interfaces/confirm-config.js +0 -1
  136. package/esm5/app/interfaces/confirm-tab-group.js +0 -1
  137. package/esm5/app/interfaces/form-deactivate.js +0 -1
  138. package/esm5/app/interfaces/index.js +0 -1
  139. package/esm5/app/interfaces/submit-event.js +0 -1
  140. package/esm5/app/interfaces/submitted-event.js +0 -1
  141. package/esm5/app/interfaces/validator.js +0 -1
  142. package/esm5/app/providers/validate-messages.provider.js +0 -12
  143. package/esm5/app/services/fsform.service.js +0 -27
  144. package/esm5/app/validators/validators.js +0 -102
  145. package/esm5/firestitch-form.js +0 -27
  146. package/esm5/public_api.js +0 -14
  147. package/fesm5/firestitch-form.js +0 -2396
  148. package/fesm5/firestitch-form.js.map +0 -1
  149. package/firestitch-form.metadata.json +0 -1
@@ -1,2396 +0,0 @@
1
- import { __decorate, __metadata, __assign, __read, __spread, __param, __extends } from 'tslib';
2
- import { HostBinding, HostListener, Directive, ɵɵdefineInjectable, Injectable, EventEmitter, QueryList, Inject, ElementRef, NgZone, Optional, Input, Output, ContentChildren, InjectionToken, Renderer2, Injector, Self, Host, ChangeDetectorRef, Component, ChangeDetectionStrategy, NgModule, ɵɵinject } from '@angular/core';
3
- import { CommonModule } from '@angular/common';
4
- import { FormGroup, NgForm, NgControl, Validators, FormsModule } from '@angular/forms';
5
- import { MatButton, MatButtonModule } from '@angular/material/button';
6
- import { MatDialogRef, MatDialogModule } from '@angular/material/dialog';
7
- import { ErrorStateMatcher, ShowOnDirtyErrorStateMatcher } from '@angular/material/core';
8
- import { MatTabGroup } from '@angular/material/tabs';
9
- import { MessageMode, FsMessage } from '@firestitch/message';
10
- import { FsPrompt } from '@firestitch/prompt';
11
- import { guid, email, isEmpty, isNumeric, phone, url } from '@firestitch/common';
12
- import { DrawerRef } from '@firestitch/drawer';
13
- import { Observable, Subject, BehaviorSubject, of, isObservable, throwError, fromEvent, iif, defer, from } from 'rxjs';
14
- import { first, filter, map, take, mergeMap, tap, switchMap, catchError, takeUntil, delay, startWith } from 'rxjs/operators';
15
- import { values, keys, isObject } from 'lodash-es';
16
- import { isValid } from 'date-fns';
17
-
18
- var ConfirmResult;
19
- (function (ConfirmResult) {
20
- ConfirmResult["Save"] = "save";
21
- ConfirmResult["Discard"] = "discard";
22
- ConfirmResult["Review"] = "review";
23
- ConfirmResult["Invalid"] = "invalid";
24
- ConfirmResult["Pristine"] = "pristine";
25
- })(ConfirmResult || (ConfirmResult = {}));
26
-
27
- function confirmUnsaved(form, prompt) {
28
- return new Observable(function (observer) {
29
- if (!form.confirm || !form.ngForm.dirty) {
30
- observer.next(ConfirmResult.Pristine);
31
- observer.complete();
32
- return;
33
- }
34
- var title = 'You Have Unsaved Changes';
35
- var message = 'What would you like to do with your changes?';
36
- var saveLabel = 'Save & Continue';
37
- var discardLabel = 'Discard Changes & Continue';
38
- var cancelLabel = 'Review Changes';
39
- if (typeof form.confirm === 'object') {
40
- title = form.confirm.title || title;
41
- message = form.confirm.message || message;
42
- saveLabel = form.confirm.saveLabel || saveLabel;
43
- discardLabel = form.confirm.discardLabel || discardLabel;
44
- cancelLabel = form.confirm.cancelLabel || cancelLabel;
45
- }
46
- prompt.confirm({
47
- title: title,
48
- template: message,
49
- dialogConfig: { width: 'auto' },
50
- buttons: [
51
- {
52
- label: saveLabel,
53
- color: 'primary',
54
- value: 'save'
55
- },
56
- {
57
- label: discardLabel,
58
- value: 'discard'
59
- },
60
- {
61
- label: cancelLabel,
62
- cancel: true
63
- }
64
- ]
65
- }).subscribe(function (value) {
66
- if (value === 'discard') {
67
- observer.next(ConfirmResult.Discard);
68
- observer.complete();
69
- form.reset();
70
- }
71
- if (value === 'save') {
72
- form.submitted
73
- .pipe(first())
74
- .subscribe(function () {
75
- observer.next(ConfirmResult.Save);
76
- observer.complete();
77
- });
78
- form.invalid
79
- .pipe(first())
80
- .subscribe(function () {
81
- observer.next(ConfirmResult.Invalid);
82
- observer.complete();
83
- });
84
- form.ngForm.control.markAsPristine();
85
- form.ngForm.ngSubmit.emit();
86
- }
87
- }, function (error) {
88
- observer.next(ConfirmResult.Review);
89
- observer.complete();
90
- });
91
- });
92
- }
93
-
94
- var FsFormDialogCloseDirective = /** @class */ (function () {
95
- function FsFormDialogCloseDirective() {
96
- this.clicked$ = new Subject();
97
- this.registered = false;
98
- this.type = 'button';
99
- }
100
- FsFormDialogCloseDirective.prototype.click = function () {
101
- this.clicked$.next();
102
- };
103
- FsFormDialogCloseDirective.prototype.ngOnDestroy = function () {
104
- this.clicked$.complete();
105
- };
106
- __decorate([
107
- HostBinding('attr.type'),
108
- __metadata("design:type", Object)
109
- ], FsFormDialogCloseDirective.prototype, "type", void 0);
110
- __decorate([
111
- HostListener('click', ['$event.target']),
112
- __metadata("design:type", Function),
113
- __metadata("design:paramtypes", []),
114
- __metadata("design:returntype", void 0)
115
- ], FsFormDialogCloseDirective.prototype, "click", null);
116
- FsFormDialogCloseDirective = __decorate([
117
- Directive({
118
- selector: '[fsFormDialogClose],[fs-form-dialog-close]'
119
- })
120
- ], FsFormDialogCloseDirective);
121
- return FsFormDialogCloseDirective;
122
- }());
123
-
124
- var FsForm = /** @class */ (function () {
125
- function FsForm() {
126
- this._eventBus = new Subject();
127
- }
128
- FsForm.prototype.broadcast = function (key, data) {
129
- this._eventBus.next({ key: key, data: data });
130
- };
131
- FsForm.prototype.on = function (key) {
132
- return this._eventBus.asObservable()
133
- .pipe(filter(function (event) { return event.key === key; }), map(function (event) { return event.data; }));
134
- };
135
- FsForm.ɵprov = ɵɵdefineInjectable({ factory: function FsForm_Factory() { return new FsForm(); }, token: FsForm, providedIn: "root" });
136
- FsForm = __decorate([
137
- Injectable({
138
- providedIn: 'root',
139
- }),
140
- __metadata("design:paramtypes", [])
141
- ], FsForm);
142
- return FsForm;
143
- }());
144
-
145
- var FormStatus;
146
- (function (FormStatus) {
147
- FormStatus["Valid"] = "valid";
148
- FormStatus["Invalid"] = "invalid";
149
- FormStatus["Submitting"] = "submitting";
150
- FormStatus["Submitted"] = "submitted";
151
- FormStatus["Error"] = "error";
152
- FormStatus["Success"] = "success";
153
- FormStatus["Completing"] = "completing";
154
- })(FormStatus || (FormStatus = {}));
155
-
156
- function confirmResultContinue(result) {
157
- return result === ConfirmResult.Discard || result === ConfirmResult.Save || result === ConfirmResult.Pristine;
158
- }
159
-
160
- function getFormErrors(control, key) {
161
- var _a;
162
- var errors = null;
163
- if (control.invalid && control.errors) {
164
- errors = (_a = {},
165
- _a[key] = __assign({}, control.errors),
166
- _a);
167
- }
168
- if (control instanceof FormGroup) {
169
- Object.entries(control.controls)
170
- .forEach(function (_a) {
171
- var _b = __read(_a, 2), name = _b[0], childControl = _b[1];
172
- var childErrors = getFormErrors(childControl, name);
173
- if (childErrors) {
174
- if (!errors) {
175
- errors = __assign({}, childErrors);
176
- }
177
- else {
178
- Object.assign(errors, childErrors);
179
- }
180
- }
181
- });
182
- }
183
- return errors;
184
- }
185
-
186
- var FsFormDirective = /** @class */ (function () {
187
- function FsFormDirective(ngForm, _form, _element, _message, _prompt, _ngZone, _dialogRef, _drawerRef) {
188
- this.ngForm = ngForm;
189
- this._form = _form;
190
- this._element = _element;
191
- this._message = _message;
192
- this._prompt = _prompt;
193
- this._ngZone = _ngZone;
194
- this._dialogRef = _dialogRef;
195
- this._drawerRef = _drawerRef;
196
- this.wrapperSelector = '.fs-form-wrapper,.mat-form-field';
197
- this.messageSelector = '.fs-form-message,.mat-form-field-subscript-wrapper';
198
- this.hintSelector = '.fs-form-hint,.mat-form-field-hint-wrapper';
199
- this.labelSelector = '.fs-form-label,.mat-form-field-label';
200
- this.autocomplete = false;
201
- this.shortcuts = true; // Ctrl + s
202
- this.confirm = true;
203
- this.confirmDialog = true;
204
- this.confirmDrawer = true;
205
- this.confirmBrowser = true;
206
- this.confirmTabs = true;
207
- this.dirtySubmitButton = true;
208
- this.successDelay = 0;
209
- this.errorDelay = 1000;
210
- this.submitEvent = new EventEmitter();
211
- this.invalid = new EventEmitter();
212
- this.valid = new EventEmitter();
213
- this.submitted = new EventEmitter();
214
- this.reseted = new EventEmitter();
215
- this.cleared = new EventEmitter();
216
- this.fsformClass = true;
217
- this._tabGroups = new QueryList();
218
- this._submitButtons = new QueryList();
219
- this._dialogBackdropEscape = false;
220
- this._snapshot = {};
221
- this._status$ = new BehaviorSubject(FormStatus.Valid);
222
- this._destroy$ = new Subject();
223
- }
224
- Object.defineProperty(FsFormDirective.prototype, "submitting", {
225
- get: function () {
226
- return this._status$.getValue() === FormStatus.Submitting;
227
- },
228
- enumerable: true,
229
- configurable: true
230
- });
231
- Object.defineProperty(FsFormDirective.prototype, "completing", {
232
- get: function () {
233
- return this._status$.getValue() === FormStatus.Completing;
234
- },
235
- enumerable: true,
236
- configurable: true
237
- });
238
- Object.defineProperty(FsFormDirective.prototype, "_submitEvent", {
239
- get: function () {
240
- return {
241
- ngForm: this.ngForm,
242
- submitter: this._submitter,
243
- };
244
- },
245
- enumerable: true,
246
- configurable: true
247
- });
248
- Object.defineProperty(FsFormDirective.prototype, "_formValidState$", {
249
- get: function () {
250
- this._form.broadcast('valid', this._submitEvent);
251
- this.submitEvent.emit(this._submitEvent);
252
- this.valid.emit(this._submitEvent);
253
- var submittedEvent = {
254
- ngForm: this.ngForm,
255
- submitter: this._submitter,
256
- response: null
257
- };
258
- if (!this.submit) {
259
- return of(submittedEvent);
260
- }
261
- var result = this.submit(this._submitEvent);
262
- if (!isObservable(result)) {
263
- return of(submittedEvent);
264
- }
265
- return result
266
- .pipe(map(function (response) {
267
- submittedEvent.response = response;
268
- return submittedEvent;
269
- }));
270
- },
271
- enumerable: true,
272
- configurable: true
273
- });
274
- Object.defineProperty(FsFormDirective.prototype, "_formInvalidState$", {
275
- get: function () {
276
- this._form.broadcast('invalid', this._submitEvent);
277
- if (this.invalid) {
278
- this.invalid.emit(this._submitEvent);
279
- }
280
- var message = 'Changes not saved. Please review errors highlighted in red.';
281
- this._message.error(message, { mode: MessageMode.Toast });
282
- var el = this._element.nativeElement.querySelector('.ng-invalid');
283
- if (el) {
284
- el.scrollIntoView({ behavior: 'smooth', block: 'center' });
285
- }
286
- return throwError('Form validation error');
287
- },
288
- enumerable: true,
289
- configurable: true
290
- });
291
- Object.defineProperty(FsFormDirective.prototype, "_submitter", {
292
- get: function () {
293
- return this._activeSubmitButton
294
- ? this._activeSubmitButton.name
295
- : null;
296
- },
297
- enumerable: true,
298
- configurable: true
299
- });
300
- FsFormDirective.prototype.ngOnInit = function () {
301
- this._registerConfirmDialogBackdropEscape();
302
- this._listenHotKeys();
303
- this._listenWindowClose();
304
- this._listenSubmit();
305
- if (!this.autocomplete) {
306
- this._registerAutocomplete();
307
- }
308
- };
309
- FsFormDirective.prototype.ngOnChanges = function (changes) {
310
- if (changes.confirm) {
311
- this._updateDirtySubmitButtons();
312
- }
313
- };
314
- FsFormDirective.prototype.ngAfterContentInit = function () {
315
- this._registerConfirm();
316
- this._registerConfirmDialogClose();
317
- this._registerConfirmDrawerClose();
318
- this._registerConfirmTabs();
319
- this._registerDrawerClose();
320
- this._registerDirtySubmitButton();
321
- };
322
- FsFormDirective.prototype.ngOnDestroy = function () {
323
- this._destroy$.next();
324
- this._destroy$.complete();
325
- };
326
- FsFormDirective.prototype.createSnapshot = function () {
327
- this._snapshot = this.ngForm.value;
328
- };
329
- FsFormDirective.prototype.reset = function () {
330
- var _this = this;
331
- this.ngForm.resetForm();
332
- Object.keys(this.ngForm.controls)
333
- .forEach(function (name) {
334
- var control = _this.ngForm.controls[name];
335
- control.reset(_this._snapshot[name]);
336
- });
337
- this.reseted.emit();
338
- };
339
- FsFormDirective.prototype.clear = function () {
340
- this.ngForm.resetForm();
341
- this.cleared.emit();
342
- };
343
- FsFormDirective.prototype.dirty = function () {
344
- this.ngForm.form.markAsDirty();
345
- this._updateDirtySubmitButtons();
346
- };
347
- FsFormDirective.prototype.triggerSubmit = function () {
348
- this.ngForm.ngSubmit.next();
349
- };
350
- FsFormDirective.prototype.triggerConfirm = function () {
351
- var _this = this;
352
- var submitted = this.submitting ? this.submitted.asObservable() : of({});
353
- return submitted
354
- .pipe(take(1), mergeMap(function () { return confirmUnsaved(_this, _this._prompt); }));
355
- };
356
- FsFormDirective.prototype.enable = function () {
357
- this.ngForm.control.enable();
358
- this._updateDirtySubmitButtons();
359
- };
360
- FsFormDirective.prototype.disable = function () {
361
- this.ngForm.control.disable();
362
- this._submitButtons.forEach(function (button) {
363
- button.disable();
364
- });
365
- };
366
- FsFormDirective.prototype.addSubmitButton = function (submitButton) {
367
- this._submitButtons.reset(__spread(this._submitButtons.toArray(), [
368
- submitButton,
369
- ]));
370
- };
371
- FsFormDirective.prototype.removeSubmitButton = function (submitButton) {
372
- this._submitButtons.reset(__spread(this._submitButtons.toArray()
373
- .filter(function (submitButton_) { return (submitButton !== submitButton_); })));
374
- };
375
- FsFormDirective.prototype._listenSubmit = function () {
376
- var _this = this;
377
- this.ngForm
378
- .ngSubmit
379
- .pipe(tap(function (event) {
380
- event === null || event === void 0 ? void 0 : event.preventDefault();
381
- }), filter(function () {
382
- return [FormStatus.Valid, FormStatus.Invalid]
383
- .includes(_this._status$.getValue());
384
- }), tap(function () { return _this._markControlsAsTouchedAndUpdateValidity(); }), tap(function () { return _this._broadcastSubmittingEvents(); }), switchMap(function () { return _this._waitUntilStatusPending(); }), tap(function () { return _this._setupActiveSubmitButton(); }), mergeMap(function () {
385
- return _this.ngForm.status === 'INVALID'
386
- ? _this._formInvalidState$
387
- : _this._formValidState$;
388
- }), catchError(function (e, source$) {
389
- _this._handleError(e);
390
- return source$;
391
- }), tap(function (submittedEvent) {
392
- _this._completeSubmit(true, submittedEvent);
393
- }), takeUntil(this._destroy$))
394
- .subscribe(function () { });
395
- };
396
- FsFormDirective.prototype._listenWindowClose = function () {
397
- var _this = this;
398
- fromEvent(window, 'beforeunload')
399
- .pipe(takeUntil(this._destroy$))
400
- .subscribe(function (event) {
401
- if (_this.confirm && _this.confirmBrowser && _this.ngForm.dirty) {
402
- event.returnValue = false;
403
- }
404
- });
405
- };
406
- FsFormDirective.prototype._listenHotKeys = function () {
407
- var _this = this;
408
- this._ngZone.runOutsideAngular(function () {
409
- fromEvent(document, 'keydown')
410
- .pipe(takeUntil(_this._destroy$))
411
- .subscribe(function (event) {
412
- if (_this._dialogBackdropEscape && event.code === 'Escape') {
413
- var dialog_1 = document.getElementById(_this._dialogRef.id);
414
- var paths = event.composedPath();
415
- if (paths) {
416
- paths.forEach(function (item) {
417
- if (dialog_1 === item) {
418
- _this._ngZone.run(function () {
419
- _this._formClose();
420
- });
421
- }
422
- });
423
- }
424
- }
425
- if ((event.ctrlKey || event.metaKey) && event.code === 'KeyS') {
426
- event.preventDefault();
427
- if (_this.shortcuts) {
428
- if (_this._elementInForm(document.activeElement)) {
429
- _this.ngForm.ngSubmit.next();
430
- }
431
- }
432
- }
433
- });
434
- });
435
- };
436
- FsFormDirective.prototype._formClose = function () {
437
- var _this = this;
438
- if (this.confirm && this.confirmDialog) {
439
- this.triggerConfirm()
440
- .pipe(filter(function (result) { return confirmResultContinue(result); }), switchMap(function (result) {
441
- return result === ConfirmResult.Pristine || result === ConfirmResult.Discard
442
- ? of(null)
443
- : _this.submitted.asObservable();
444
- }), takeUntil(this._destroy$))
445
- .subscribe(function (result) {
446
- _this._dialogRef.close(result === null || result === void 0 ? void 0 : result.response);
447
- });
448
- }
449
- else {
450
- this._dialogRef.close(null);
451
- }
452
- };
453
- FsFormDirective.prototype._registerDialogClose = function (directive) {
454
- var _this = this;
455
- if (!directive.registered) {
456
- directive.registered = true;
457
- directive.clicked$
458
- .pipe(takeUntil(this._destroy$))
459
- .subscribe(function () {
460
- _this._formClose();
461
- });
462
- }
463
- };
464
- FsFormDirective.prototype._getActiveButton = function () {
465
- var activeButton = this._submitButtons.find(function (button) {
466
- return button.active;
467
- });
468
- return activeButton ? activeButton : this._submitButtons.first;
469
- };
470
- FsFormDirective.prototype._elementInForm = function (el) {
471
- if (el.isSameNode(this._element.nativeElement)) {
472
- return true;
473
- }
474
- else if (el.parentElement) {
475
- return this._elementInForm(el.parentElement);
476
- }
477
- return false;
478
- };
479
- FsFormDirective.prototype._completeSubmit = function (success, submitEvent) {
480
- var _this = this;
481
- if (success) {
482
- this.ngForm.control.markAsPristine();
483
- this.createSnapshot();
484
- this.submitted.emit(submitEvent);
485
- }
486
- else {
487
- this._resetButtons();
488
- }
489
- if (this._activeSubmitButton) {
490
- if (success) {
491
- this._activeSubmitButton.success();
492
- }
493
- else {
494
- this._activeSubmitButton.error();
495
- }
496
- }
497
- this._status$.next(FormStatus.Submitted);
498
- if (success) {
499
- this._status$.next(FormStatus.Success);
500
- }
501
- else {
502
- this._status$.next(FormStatus.Error);
503
- }
504
- this._status$.next(FormStatus.Completing);
505
- var resetDelay = success ? this.successDelay : this.errorDelay;
506
- of(true)
507
- .pipe(delay(resetDelay), first(), takeUntil(this._destroy$)).subscribe(function () {
508
- if (_this.ngForm.form.status === 'VALID') {
509
- _this._status$.next(FormStatus.Valid);
510
- }
511
- else {
512
- _this._status$.next(FormStatus.Invalid);
513
- }
514
- _this._resetButtons();
515
- _this._updateDirtySubmitButtons();
516
- });
517
- };
518
- FsFormDirective.prototype._resetButtons = function () {
519
- this._submitButtons.forEach(function (button) {
520
- button.reset();
521
- });
522
- };
523
- FsFormDirective.prototype._registerConfirm = function () {
524
- var _this = this;
525
- this.ngForm.form.valueChanges
526
- .pipe(takeUntil(this._destroy$))
527
- .subscribe(function (changes) {
528
- if (_this.confirm) {
529
- var existing_1 = Object.keys(_this._snapshot);
530
- Object.keys(changes)
531
- .forEach(function (name) {
532
- if (existing_1.indexOf(name) === -1) {
533
- _this._snapshot[name] = changes[name];
534
- }
535
- });
536
- }
537
- });
538
- };
539
- FsFormDirective.prototype._registerDrawerClose = function () {
540
- var _this = this;
541
- if (this._drawerRef) {
542
- this._drawerRef.closeStart$
543
- .pipe(takeUntil(this._destroy$))
544
- .subscribe(function (subscriber) {
545
- if (_this.submitting) {
546
- _this._status$
547
- .pipe(filter(function (status) { return status === FormStatus.Success || status === FormStatus.Error; }), takeUntil(_this._destroy$))
548
- .subscribe(function (status) {
549
- if (status === FormStatus.Success) {
550
- subscriber.next();
551
- subscriber.complete();
552
- }
553
- else {
554
- subscriber.error();
555
- }
556
- });
557
- }
558
- else {
559
- subscriber.next();
560
- subscriber.complete();
561
- }
562
- });
563
- }
564
- };
565
- FsFormDirective.prototype._registerConfirmDrawerClose = function () {
566
- var _this = this;
567
- if (this._drawerRef) {
568
- this._drawerRef.closeStart$
569
- .pipe(switchMap(function (subscriber) {
570
- return iif(function () { return _this.confirm && _this.confirmDrawer; }, _this.triggerConfirm()
571
- .pipe(map(function (result) { return confirmResultContinue(result); }), tap(function (result) {
572
- if (result) {
573
- subscriber.next();
574
- subscriber.complete();
575
- }
576
- })), defer(function () {
577
- subscriber.next();
578
- subscriber.complete();
579
- }));
580
- }), takeUntil(this._destroy$))
581
- .subscribe();
582
- }
583
- };
584
- FsFormDirective.prototype._registerConfirmTabs = function () {
585
- var _this = this;
586
- if (this.tabGroup) {
587
- this.registerConfirmTabGroup(this.tabGroup);
588
- }
589
- this.registerConfirmTabGroups(this._tabGroups.toArray());
590
- this._tabGroups.changes
591
- .pipe(takeUntil(this._destroy$))
592
- .subscribe(function () {
593
- _this.registerConfirmTabGroups(_this._tabGroups.toArray());
594
- });
595
- };
596
- FsFormDirective.prototype.registerConfirmTabGroups = function (tabGroups) {
597
- var _this = this;
598
- tabGroups.forEach(function (tabGroup) {
599
- _this.registerConfirmTabGroup(tabGroup);
600
- });
601
- };
602
- FsFormDirective.prototype.registerConfirmTabGroup = function (tabGroup) {
603
- var _this = this;
604
- var confirmTabGroup = tabGroup;
605
- if (!confirmTabGroup._originalHandleClick) {
606
- confirmTabGroup._originalHandleClick = tabGroup._handleClick;
607
- confirmTabGroup._handlClick$ = new Subject();
608
- confirmTabGroup._handleClick = function (tab, tabHeader, idx) {
609
- if (confirmTabGroup._handlClick$.observers.length) {
610
- confirmTabGroup._handlClick$.next({ tab: tab, tabHeader: tabHeader, idx: idx });
611
- }
612
- else {
613
- confirmTabGroup._originalHandleClick(tab, tabHeader, idx);
614
- }
615
- };
616
- }
617
- confirmTabGroup._handlClick$
618
- .pipe(takeUntil(this._destroy$))
619
- .subscribe(function (event) {
620
- if (!_this.submitting) {
621
- if (_this.confirm && _this.confirmTabs) {
622
- _this.triggerConfirm()
623
- .pipe(takeUntil(_this._destroy$))
624
- .subscribe(function (result) {
625
- if (confirmResultContinue(result)) {
626
- confirmTabGroup.selectedIndex = event.idx;
627
- }
628
- });
629
- }
630
- else {
631
- confirmTabGroup._originalHandleClick(event.tab, event.tabHeader, event.idx);
632
- }
633
- }
634
- });
635
- };
636
- FsFormDirective.prototype._registerConfirmDialogClose = function () {
637
- var _this = this;
638
- if (this._dialogRef) {
639
- this.formDialogClose.forEach(function (item) {
640
- _this._registerDialogClose(item);
641
- });
642
- this.formDialogClose.changes
643
- .pipe(takeUntil(this._destroy$))
644
- .subscribe(function (e) {
645
- e.forEach(function (item) {
646
- _this._registerDialogClose(item);
647
- });
648
- });
649
- }
650
- };
651
- FsFormDirective.prototype._registerConfirmDialogBackdropEscape = function () {
652
- var _this = this;
653
- this._dialogBackdropEscape = this._dialogRef && this._dialogRef.disableClose !== true;
654
- if (this._dialogRef && !this._dialogRef.disableClose) {
655
- this._dialogRef.disableClose = true;
656
- this._dialogRef.backdropClick()
657
- .pipe(takeUntil(this._destroy$))
658
- .subscribe(function () {
659
- _this._formClose();
660
- });
661
- this._destroy$
662
- .subscribe(function () {
663
- _this._dialogRef.disableClose = false;
664
- });
665
- }
666
- };
667
- FsFormDirective.prototype._registerAutocomplete = function () {
668
- var _this = this;
669
- this._registerControl = this.ngForm.form.registerControl.bind(this.ngForm.form);
670
- this.ngForm.form.registerControl = function (name, control) {
671
- var el = _this._element.nativeElement.querySelector("input[name='" + name + "']");
672
- if (el) {
673
- el.setAttribute('name', name + '_' + guid());
674
- if (!el.getAttribute('autocomplete')) {
675
- el.setAttribute('autocomplete', 'none');
676
- }
677
- }
678
- return _this._registerControl(name, control);
679
- };
680
- };
681
- FsFormDirective.prototype._registerDirtySubmitButton = function () {
682
- var _this = this;
683
- if (!this.ngForm) {
684
- return;
685
- }
686
- this.ngForm.form.valueChanges
687
- .pipe(takeUntil(this._destroy$))
688
- .subscribe(function () {
689
- _this._updateDirtySubmitButtons();
690
- });
691
- this._submitButtons.changes
692
- .pipe(takeUntil(this._destroy$))
693
- .subscribe(function () {
694
- _this._updateDirtySubmitButtons();
695
- });
696
- };
697
- FsFormDirective.prototype._updateDirtySubmitButtons = function () {
698
- var _this = this;
699
- this._submitButtons
700
- .forEach(function (submitButton) {
701
- if (!_this.confirm || !_this.dirtySubmitButton || _this.ngForm.dirty || !submitButton.dirtySubmit) {
702
- submitButton.enable();
703
- }
704
- else {
705
- submitButton.disable();
706
- }
707
- });
708
- };
709
- FsFormDirective.prototype._broadcastSubmittingEvents = function () {
710
- this._status$.next(FormStatus.Submitting);
711
- this._form.broadcast('submit', this.ngForm);
712
- };
713
- FsFormDirective.prototype._markControlsAsTouchedAndUpdateValidity = function () {
714
- Object.values(this.ngForm.controls)
715
- .forEach(function (control) {
716
- control.markAsDirty();
717
- control.markAsTouched();
718
- control.updateValueAndValidity();
719
- });
720
- };
721
- FsFormDirective.prototype._setupActiveSubmitButton = function () {
722
- this._activeSubmitButton = this._getActiveButton();
723
- this._resetButtons();
724
- if (this._activeSubmitButton) {
725
- this._activeSubmitButton.process();
726
- }
727
- };
728
- FsFormDirective.prototype._waitUntilStatusPending = function () {
729
- return this.ngForm.statusChanges
730
- .pipe(startWith(this.ngForm.status), first(function (state) { return state !== 'PENDING'; }));
731
- };
732
- FsFormDirective.prototype._handleError = function (e) {
733
- console.log('%c Form Submit ', 'color: white; background-color: #D33F49', 'Error occured');
734
- console.group('Error Details:');
735
- console.log('Message: ', e);
736
- console.log('FormRef: ', this);
737
- if (this.ngForm.invalid) {
738
- var errors = getFormErrors(this.ngForm.control, null);
739
- console.log('Validation Errors: ', errors);
740
- }
741
- console.groupEnd();
742
- this._completeSubmit(false, null);
743
- };
744
- FsFormDirective.ctorParameters = function () { return [
745
- { type: NgForm, decorators: [{ type: Inject, args: [NgForm,] }] },
746
- { type: FsForm },
747
- { type: ElementRef },
748
- { type: FsMessage },
749
- { type: FsPrompt },
750
- { type: NgZone },
751
- { type: MatDialogRef, decorators: [{ type: Optional }, { type: Inject, args: [MatDialogRef,] }] },
752
- { type: DrawerRef, decorators: [{ type: Optional }, { type: Inject, args: [DrawerRef,] }] }
753
- ]; };
754
- __decorate([
755
- Input(),
756
- __metadata("design:type", Object)
757
- ], FsFormDirective.prototype, "wrapperSelector", void 0);
758
- __decorate([
759
- Input(),
760
- __metadata("design:type", Object)
761
- ], FsFormDirective.prototype, "messageSelector", void 0);
762
- __decorate([
763
- Input(),
764
- __metadata("design:type", Object)
765
- ], FsFormDirective.prototype, "hintSelector", void 0);
766
- __decorate([
767
- Input(),
768
- __metadata("design:type", Object)
769
- ], FsFormDirective.prototype, "labelSelector", void 0);
770
- __decorate([
771
- Input(),
772
- __metadata("design:type", Object)
773
- ], FsFormDirective.prototype, "autocomplete", void 0);
774
- __decorate([
775
- Input(),
776
- __metadata("design:type", Object)
777
- ], FsFormDirective.prototype, "shortcuts", void 0);
778
- __decorate([
779
- Input(),
780
- __metadata("design:type", Object)
781
- ], FsFormDirective.prototype, "confirm", void 0);
782
- __decorate([
783
- Input(),
784
- __metadata("design:type", Object)
785
- ], FsFormDirective.prototype, "confirmDialog", void 0);
786
- __decorate([
787
- Input(),
788
- __metadata("design:type", Object)
789
- ], FsFormDirective.prototype, "confirmDrawer", void 0);
790
- __decorate([
791
- Input(),
792
- __metadata("design:type", Object)
793
- ], FsFormDirective.prototype, "confirmBrowser", void 0);
794
- __decorate([
795
- Input(),
796
- __metadata("design:type", Object)
797
- ], FsFormDirective.prototype, "confirmTabs", void 0);
798
- __decorate([
799
- Input(),
800
- __metadata("design:type", Object)
801
- ], FsFormDirective.prototype, "dirtySubmitButton", void 0);
802
- __decorate([
803
- Input(),
804
- __metadata("design:type", Function)
805
- ], FsFormDirective.prototype, "submit", void 0);
806
- __decorate([
807
- Input(),
808
- __metadata("design:type", Object)
809
- ], FsFormDirective.prototype, "successDelay", void 0);
810
- __decorate([
811
- Input(),
812
- __metadata("design:type", Object)
813
- ], FsFormDirective.prototype, "errorDelay", void 0);
814
- __decorate([
815
- Input(),
816
- __metadata("design:type", MatTabGroup)
817
- ], FsFormDirective.prototype, "tabGroup", void 0);
818
- __decorate([
819
- Output('fsForm'),
820
- __metadata("design:type", EventEmitter)
821
- ], FsFormDirective.prototype, "submitEvent", void 0);
822
- __decorate([
823
- Output(),
824
- __metadata("design:type", EventEmitter)
825
- ], FsFormDirective.prototype, "invalid", void 0);
826
- __decorate([
827
- Output(),
828
- __metadata("design:type", EventEmitter)
829
- ], FsFormDirective.prototype, "valid", void 0);
830
- __decorate([
831
- Output(),
832
- __metadata("design:type", EventEmitter)
833
- ], FsFormDirective.prototype, "submitted", void 0);
834
- __decorate([
835
- Output(),
836
- __metadata("design:type", EventEmitter)
837
- ], FsFormDirective.prototype, "reseted", void 0);
838
- __decorate([
839
- Output(),
840
- __metadata("design:type", EventEmitter)
841
- ], FsFormDirective.prototype, "cleared", void 0);
842
- __decorate([
843
- HostBinding('class.fs-form'),
844
- __metadata("design:type", Object)
845
- ], FsFormDirective.prototype, "fsformClass", void 0);
846
- __decorate([
847
- ContentChildren(FsFormDialogCloseDirective, { descendants: true }),
848
- __metadata("design:type", QueryList)
849
- ], FsFormDirective.prototype, "formDialogClose", void 0);
850
- __decorate([
851
- ContentChildren(MatTabGroup, { descendants: true }),
852
- __metadata("design:type", QueryList)
853
- ], FsFormDirective.prototype, "_tabGroups", void 0);
854
- FsFormDirective = __decorate([
855
- Directive({
856
- selector: '[fsForm]',
857
- }),
858
- __param(0, Inject(NgForm)),
859
- __param(6, Optional()), __param(6, Inject(MatDialogRef)),
860
- __param(7, Optional()), __param(7, Inject(DrawerRef)),
861
- __metadata("design:paramtypes", [NgForm,
862
- FsForm,
863
- ElementRef,
864
- FsMessage,
865
- FsPrompt,
866
- NgZone,
867
- MatDialogRef,
868
- DrawerRef])
869
- ], FsFormDirective);
870
- return FsFormDirective;
871
- }());
872
-
873
- var ERROR_MESSAGES = {
874
- required: 'This field is required',
875
- email: 'This is not a valid email address',
876
- emails: 'Input valid email addresses, comma separated',
877
- phone: 'Invalid phone number',
878
- numeric: 'Value should be numeric',
879
- integer: 'Value should be an integer',
880
- min: 'Value should not be less than $(1)',
881
- max: 'Value should not be greater than $(1)',
882
- minlength: 'Should not be shorter than $(1) characters',
883
- maxlength: 'Should not be longer than $(1) characters',
884
- compare: 'Inputs do not match',
885
- pattern: 'Value should match pattern $(1)',
886
- dateRange: 'Invalid date range',
887
- url: 'This is not a valid url',
888
- urlProtocol: 'Invalid URL. Proper http protocol is required. eg. https://google.com',
889
- greater: 'Value must be greater than $(1)',
890
- lesser: 'Value must be less than $(1)',
891
- };
892
-
893
- var VALIDATE_MESSAGES = new InjectionToken('fs.form.validate-messages');
894
- var VALIDATE_MESSAGE_PROVIDER = {
895
- provide: VALIDATE_MESSAGES,
896
- useFactory: messageProviderFactory,
897
- };
898
- function messageProviderFactory() {
899
- return __assign({}, ERROR_MESSAGES);
900
- }
901
-
902
- var FsControlDirective = /** @class */ (function () {
903
- function FsControlDirective(elementRef, renderer2, injector, _validateMessages, ngControl, formDirective) {
904
- this.elementRef = elementRef;
905
- this.renderer2 = renderer2;
906
- this.injector = injector;
907
- this._validateMessages = _validateMessages;
908
- this.ngControl = ngControl;
909
- this.formDirective = formDirective;
910
- this.appendMessageClass = 'fs-form-message';
911
- this.appendLabelClass = 'fs-form-label';
912
- this.appendErrorClass = 'fs-form-error';
913
- this.appendHintClass = 'fs-form-hint';
914
- this.errors = [];
915
- // protected _validateMessages = { ...ERROR_MESSAGES };
916
- this._destroy$ = new Subject();
917
- if (ngControl) {
918
- this._control = ngControl.control;
919
- }
920
- else {
921
- console.error('The element does not have a valid ngModel', this.elementRef.nativeElement);
922
- }
923
- }
924
- Object.defineProperty(FsControlDirective.prototype, "validateMessages", {
925
- set: function (messages) {
926
- this._validateMessages = __assign(__assign({}, this._validateMessages), messages);
927
- },
928
- enumerable: true,
929
- configurable: true
930
- });
931
- FsControlDirective.prototype.ngOnInit = function () {
932
- this._setupValidators();
933
- };
934
- FsControlDirective.prototype.ngOnDestroy = function () {
935
- this._destroy$.next();
936
- this._destroy$.complete();
937
- };
938
- FsControlDirective.prototype.ngAfterContentInit = function () {
939
- if (this._control) {
940
- /*
941
- Ensure that statusChanges has one subscription per control. Multiple can happen
942
- when multiple fsForm validation directives are applied to the same element
943
- */
944
- if (!this._control.statusChangesSubscribe) {
945
- this._control.statusChanges
946
- .pipe(takeUntil(this._destroy$))
947
- .subscribe(this.render.bind(this));
948
- this._control.statusChangesSubscribe = true;
949
- }
950
- }
951
- };
952
- FsControlDirective.prototype.getMessageSelector = function () {
953
- if (this.messageSelector === false) {
954
- return '';
955
- }
956
- if (this.messageSelector) {
957
- return this.messageSelector;
958
- }
959
- else if (this.formDirective && this.formDirective.messageSelector) {
960
- return this.formDirective.messageSelector;
961
- }
962
- };
963
- FsControlDirective.prototype.getHintWrapperSelector = function () {
964
- if (this.hintSelector === false) {
965
- return '';
966
- }
967
- if (this.hintSelector) {
968
- return this.hintSelector;
969
- }
970
- else if (this.formDirective && this.formDirective.hintSelector) {
971
- return this.formDirective.hintSelector;
972
- }
973
- };
974
- FsControlDirective.prototype.getWrapperSelector = function () {
975
- if (this.wrapperSelector === false) {
976
- return '';
977
- }
978
- if (this.wrapperSelector) {
979
- return this.wrapperSelector;
980
- }
981
- else if (this.formDirective && this.formDirective.wrapperSelector) {
982
- return this.formDirective.wrapperSelector;
983
- }
984
- };
985
- FsControlDirective.prototype.getlabelSelector = function () {
986
- if (this.labelSelector === false) {
987
- return '';
988
- }
989
- if (this.labelSelector) {
990
- return this.labelSelector;
991
- }
992
- else if (this.formDirective && this.formDirective.labelSelector) {
993
- return this.formDirective.labelSelector;
994
- }
995
- };
996
- FsControlDirective.prototype.getWrapperElement = function () {
997
- var wrapper = this.getWrapper(this.elementRef.nativeElement);
998
- if (wrapper) {
999
- return wrapper;
1000
- }
1001
- return this.elementRef.nativeElement;
1002
- };
1003
- /*
1004
- <mat-form-field class="mat-form-field"> <-- Field Wrapper Class. Look for parents from the native element with the matching wrapperSelector. If not found defaults to native element.
1005
- <input>
1006
- <div class="fs-form-message"> <-- Message Selector. Look for the element with class .fs-form-message or messageSelector
1007
- <div class="fs-form-message"></div>
1008
- <div class="fs-form-hint"></div> <-- Hint Selector. Look for the element with class .fs-form-hint or hintSelector
1009
- </div>
1010
- </mat-form-field>
1011
- */
1012
- FsControlDirective.prototype.render = function () {
1013
- var _a;
1014
- if (this.ngControl) {
1015
- var renderer = this.renderer2;
1016
- var wrapper = this.getWrapperElement();
1017
- var error = this.ngControl.dirty ? this.getError(this.ngControl) : null;
1018
- if (!this.getMessageSelector()) {
1019
- return;
1020
- }
1021
- var messageWrapper = wrapper.querySelector(this.getMessageSelector());
1022
- if (!messageWrapper) {
1023
- return console.warn('Failed to locate ' + this.getMessageSelector(), this.elementRef.nativeElement);
1024
- }
1025
- if (this.getlabelSelector()) {
1026
- var labelWrapper = wrapper.querySelector(this.getlabelSelector());
1027
- if (labelWrapper) {
1028
- if (this.appendLabelClass) {
1029
- this.renderer2.addClass(labelWrapper, this.appendLabelClass);
1030
- }
1031
- }
1032
- }
1033
- if (this.appendMessageClass) {
1034
- renderer.addClass(messageWrapper, this.appendMessageClass);
1035
- }
1036
- if (this.getHintWrapperSelector()) {
1037
- var hint = messageWrapper.querySelector(this.getHintWrapperSelector());
1038
- if (hint) {
1039
- renderer.setStyle(hint, 'display', error ? 'none' : 'block');
1040
- if (this.appendHintClass) {
1041
- renderer.addClass(hint, this.appendHintClass);
1042
- }
1043
- }
1044
- }
1045
- var errorWrapper = wrapper.querySelector('.fs-form-error-target');
1046
- if (errorWrapper) {
1047
- errorWrapper.remove();
1048
- }
1049
- wrapper.classList.remove('ng-invalid');
1050
- var shouldErrorBeRendered = this.ngControl.invalid
1051
- && (this.ngControl.dirty || ((_a = this.formDirective.ngForm) === null || _a === void 0 ? void 0 : _a.submitted));
1052
- if (!shouldErrorBeRendered || !error) {
1053
- return;
1054
- }
1055
- wrapper.classList.add('ng-invalid');
1056
- errorWrapper = renderer.createElement('div');
1057
- renderer.addClass(errorWrapper, 'fs-form-error-target');
1058
- renderer.addClass(errorWrapper, this.appendErrorClass);
1059
- renderer.addClass(errorWrapper, this.appendErrorClass + '-' + error.name);
1060
- var errorText = renderer.createText(error.message);
1061
- renderer.appendChild(errorWrapper, errorText);
1062
- messageWrapper.appendChild(errorWrapper);
1063
- }
1064
- };
1065
- FsControlDirective.prototype.getWrapper = function (node, count) {
1066
- if (count === void 0) { count = 0; }
1067
- if (!node || count > 10) {
1068
- return null;
1069
- }
1070
- if (node.parentNode && node.parentNode.querySelector(this.getWrapperSelector())) {
1071
- return node;
1072
- }
1073
- return this.getWrapper(node.parentNode, ++count);
1074
- };
1075
- FsControlDirective.prototype.parseErrorMessage = function (message, args) {
1076
- values(args)
1077
- .forEach(function (name) {
1078
- message = message.replace(/\$\(\d\)/, name);
1079
- });
1080
- return message;
1081
- };
1082
- FsControlDirective.prototype.getError = function (controlRef) {
1083
- var name = keys(controlRef.control.errors)[0];
1084
- if (!name) {
1085
- return null;
1086
- }
1087
- var message = controlRef.control.errors[name];
1088
- if (this._validateMessages[name]) {
1089
- message = this.parseErrorMessage(this._validateMessages[name], message);
1090
- }
1091
- return { name: name, message: message };
1092
- };
1093
- FsControlDirective.prototype._setupValidators = function () {
1094
- var control = this._control;
1095
- if (this.validate) {
1096
- var validators = control.validator
1097
- ? [control.validator, this.validate.bind(this)]
1098
- : this.validate.bind(this);
1099
- control.setValidators(validators);
1100
- }
1101
- if (this.validateAsync) {
1102
- var asyncValidators = control.asyncValidator
1103
- ? [control.asyncValidator, this.validateAsync.bind(this)]
1104
- : this.validateAsync.bind(this);
1105
- control.setAsyncValidators(asyncValidators);
1106
- }
1107
- control.updateValueAndValidity();
1108
- };
1109
- FsControlDirective.ctorParameters = function () { return [
1110
- { type: ElementRef },
1111
- { type: Renderer2 },
1112
- { type: Injector },
1113
- { type: undefined, decorators: [{ type: Self }, { type: Inject, args: [VALIDATE_MESSAGES,] }] },
1114
- { type: NgControl, decorators: [{ type: Optional }] },
1115
- { type: FsFormDirective, decorators: [{ type: Optional }, { type: Inject, args: [FsFormDirective,] }] }
1116
- ]; };
1117
- __decorate([
1118
- Input(),
1119
- __metadata("design:type", Object)
1120
- ], FsControlDirective.prototype, "wrapperSelector", void 0);
1121
- __decorate([
1122
- Input(),
1123
- __metadata("design:type", Object)
1124
- ], FsControlDirective.prototype, "messageSelector", void 0);
1125
- __decorate([
1126
- Input(),
1127
- __metadata("design:type", Object)
1128
- ], FsControlDirective.prototype, "hintSelector", void 0);
1129
- __decorate([
1130
- Input(),
1131
- __metadata("design:type", Object)
1132
- ], FsControlDirective.prototype, "labelSelector", void 0);
1133
- __decorate([
1134
- Input(),
1135
- __metadata("design:type", Object)
1136
- ], FsControlDirective.prototype, "appendMessageClass", void 0);
1137
- __decorate([
1138
- Input(),
1139
- __metadata("design:type", Object)
1140
- ], FsControlDirective.prototype, "appendLabelClass", void 0);
1141
- __decorate([
1142
- Input(),
1143
- __metadata("design:type", Object)
1144
- ], FsControlDirective.prototype, "appendErrorClass", void 0);
1145
- __decorate([
1146
- Input(),
1147
- __metadata("design:type", Object)
1148
- ], FsControlDirective.prototype, "appendHintClass", void 0);
1149
- __decorate([
1150
- Input(),
1151
- __metadata("design:type", Object),
1152
- __metadata("design:paramtypes", [Object])
1153
- ], FsControlDirective.prototype, "validateMessages", null);
1154
- FsControlDirective = __decorate([
1155
- Directive({
1156
- selector: '[fsFormControl]',
1157
- providers: [
1158
- VALIDATE_MESSAGE_PROVIDER
1159
- ],
1160
- }),
1161
- __param(3, Self()), __param(3, Inject(VALIDATE_MESSAGES)),
1162
- __param(4, Optional()),
1163
- __param(5, Optional()), __param(5, Inject(FsFormDirective)),
1164
- __metadata("design:paramtypes", [ElementRef,
1165
- Renderer2,
1166
- Injector, Object, NgControl,
1167
- FsFormDirective])
1168
- ], FsControlDirective);
1169
- return FsControlDirective;
1170
- }());
1171
-
1172
- function isEnabled(value) {
1173
- return value !== 'false' && (value || value === '');
1174
- }
1175
-
1176
- var FsFormRequiredDirective = /** @class */ (function (_super) {
1177
- __extends(FsFormRequiredDirective, _super);
1178
- function FsFormRequiredDirective() {
1179
- var _this = _super !== null && _super.apply(this, arguments) || this;
1180
- _this.required = false;
1181
- return _this;
1182
- }
1183
- Object.defineProperty(FsFormRequiredDirective.prototype, "setFsFormRequired", {
1184
- set: function (value) {
1185
- this.required = isEnabled(value);
1186
- },
1187
- enumerable: true,
1188
- configurable: true
1189
- });
1190
- Object.defineProperty(FsFormRequiredDirective.prototype, "setRequired", {
1191
- set: function (value) {
1192
- this.required = isEnabled(value);
1193
- },
1194
- enumerable: true,
1195
- configurable: true
1196
- });
1197
- Object.defineProperty(FsFormRequiredDirective.prototype, "validationMessage", {
1198
- set: function (value) {
1199
- this._validateMessages.required = value;
1200
- },
1201
- enumerable: true,
1202
- configurable: true
1203
- });
1204
- FsFormRequiredDirective.prototype.ngOnChanges = function () {
1205
- this._control.updateValueAndValidity();
1206
- };
1207
- FsFormRequiredDirective.prototype.validate = function (control) {
1208
- if (this.required) {
1209
- return Validators.required(this._control);
1210
- }
1211
- else {
1212
- return null;
1213
- }
1214
- };
1215
- FsFormRequiredDirective.prototype.render = function () {
1216
- var wrapper = this.getWrapperElement();
1217
- if (wrapper && this.getlabelSelector()) {
1218
- var labelWrapper = wrapper.querySelector(this.getlabelSelector());
1219
- // Adding class fs-form-label-requried adds the * to the label
1220
- if (labelWrapper) {
1221
- if (this.required) {
1222
- this.renderer2.addClass(labelWrapper, 'fs-form-label-required');
1223
- }
1224
- else {
1225
- this.renderer2.removeClass(labelWrapper, 'fs-form-label-required');
1226
- }
1227
- }
1228
- }
1229
- _super.prototype.render.call(this);
1230
- };
1231
- __decorate([
1232
- Input('fsFormRequired'),
1233
- __metadata("design:type", Object),
1234
- __metadata("design:paramtypes", [Object])
1235
- ], FsFormRequiredDirective.prototype, "setFsFormRequired", null);
1236
- __decorate([
1237
- Input('required'),
1238
- __metadata("design:type", Object),
1239
- __metadata("design:paramtypes", [Object])
1240
- ], FsFormRequiredDirective.prototype, "setRequired", null);
1241
- __decorate([
1242
- Input('fsFormRequiredMessage'),
1243
- __metadata("design:type", String),
1244
- __metadata("design:paramtypes", [String])
1245
- ], FsFormRequiredDirective.prototype, "validationMessage", null);
1246
- FsFormRequiredDirective = __decorate([
1247
- Directive({
1248
- selector: '[fsFormRequired],[ngModel][required]',
1249
- providers: [
1250
- VALIDATE_MESSAGE_PROVIDER
1251
- ],
1252
- })
1253
- ], FsFormRequiredDirective);
1254
- return FsFormRequiredDirective;
1255
- }(FsControlDirective));
1256
-
1257
- var FsValidators = /** @class */ (function () {
1258
- function FsValidators() {
1259
- }
1260
- FsValidators.email = function (control) {
1261
- if (!control.value || email(control.value)) {
1262
- return null;
1263
- }
1264
- return { email: true };
1265
- };
1266
- FsValidators.emails = function (control) {
1267
- var model = control.value || '';
1268
- var hasInvalidEmails = model
1269
- .split(',')
1270
- .some(function (part) { return !email(part); });
1271
- return hasInvalidEmails ? { email: true } : null;
1272
- };
1273
- FsValidators.numeric = function (control) {
1274
- if (isEmpty(control.value) || isNumeric(control.value)) {
1275
- return null;
1276
- }
1277
- else {
1278
- return { numeric: true };
1279
- }
1280
- };
1281
- FsValidators.integer = function (control) {
1282
- if (!control.value || String(control.value) === '' || (control.value % 1 === 0)) {
1283
- return null;
1284
- }
1285
- else {
1286
- return { integer: true };
1287
- }
1288
- };
1289
- FsValidators.phone = function (control) {
1290
- if (!control.value || phone(control.value)) {
1291
- return null;
1292
- }
1293
- return { phone: true };
1294
- };
1295
- FsValidators.url = function (control, protocolRequired) {
1296
- if (protocolRequired === void 0) { protocolRequired = false; }
1297
- if (!control.value) {
1298
- return null;
1299
- }
1300
- if (!url(control.value)) {
1301
- return { url: true };
1302
- }
1303
- if (protocolRequired) {
1304
- var pattern = new RegExp(/^http(s)?:\/\//gm);
1305
- if (!String(control.value).match(pattern)) {
1306
- return { urlProtocol: true };
1307
- }
1308
- }
1309
- return null;
1310
- };
1311
- FsValidators.dateRange = function (control) {
1312
- if (!control.value) {
1313
- return null;
1314
- }
1315
- if (isObject(control.value)) {
1316
- var start = control.value.start;
1317
- var end = control.value.end;
1318
- if ((!start && !end) || (isValid(start) && isValid(end))) {
1319
- return null;
1320
- }
1321
- }
1322
- return { dateRange: true };
1323
- };
1324
- FsValidators.func = function (control, formFunction, data) {
1325
- var result;
1326
- var stream$;
1327
- try {
1328
- result = formFunction(control, data);
1329
- }
1330
- catch (err) {
1331
- err = err instanceof Error ? err.message : err;
1332
- stream$ = throwError(err);
1333
- }
1334
- if (!stream$) {
1335
- if (result instanceof Promise) {
1336
- stream$ = from(result);
1337
- }
1338
- else if (isObservable(result)) {
1339
- stream$ = result;
1340
- }
1341
- else {
1342
- stream$ = of(null);
1343
- }
1344
- }
1345
- return stream$
1346
- .pipe(map(function () { return null; }), catchError(function (err) {
1347
- return of({ validationError: err });
1348
- }), take(1));
1349
- };
1350
- return FsValidators;
1351
- }());
1352
-
1353
- var FsFormMinDirective = /** @class */ (function (_super) {
1354
- __extends(FsFormMinDirective, _super);
1355
- function FsFormMinDirective() {
1356
- return _super !== null && _super.apply(this, arguments) || this;
1357
- }
1358
- Object.defineProperty(FsFormMinDirective.prototype, "validationMessage", {
1359
- set: function (value) {
1360
- this._validateMessages.min = value;
1361
- },
1362
- enumerable: true,
1363
- configurable: true
1364
- });
1365
- FsFormMinDirective.prototype.ngOnChanges = function () {
1366
- this._control.updateValueAndValidity();
1367
- };
1368
- FsFormMinDirective.prototype.validate = function (control) {
1369
- return FsValidators.numeric(this._control) || Validators.min(parseFloat(this.fsFormMin))(this._control);
1370
- };
1371
- __decorate([
1372
- Input(),
1373
- __metadata("design:type", Object)
1374
- ], FsFormMinDirective.prototype, "fsFormMin", void 0);
1375
- __decorate([
1376
- Input('fsFormMinMessage'),
1377
- __metadata("design:type", String),
1378
- __metadata("design:paramtypes", [String])
1379
- ], FsFormMinDirective.prototype, "validationMessage", null);
1380
- FsFormMinDirective = __decorate([
1381
- Directive({
1382
- selector: '[fsFormMin]',
1383
- providers: [
1384
- VALIDATE_MESSAGE_PROVIDER
1385
- ],
1386
- })
1387
- ], FsFormMinDirective);
1388
- return FsFormMinDirective;
1389
- }(FsControlDirective));
1390
-
1391
- var FsFormMaxDirective = /** @class */ (function (_super) {
1392
- __extends(FsFormMaxDirective, _super);
1393
- function FsFormMaxDirective() {
1394
- return _super !== null && _super.apply(this, arguments) || this;
1395
- }
1396
- Object.defineProperty(FsFormMaxDirective.prototype, "validationMessage", {
1397
- set: function (value) {
1398
- this._validateMessages.max = value;
1399
- },
1400
- enumerable: true,
1401
- configurable: true
1402
- });
1403
- FsFormMaxDirective.prototype.ngOnChanges = function () {
1404
- this._control.updateValueAndValidity();
1405
- };
1406
- FsFormMaxDirective.prototype.validate = function (control) {
1407
- return FsValidators.numeric(this._control) || Validators.max(this.fsFormMax)(this._control);
1408
- };
1409
- __decorate([
1410
- Input(),
1411
- __metadata("design:type", Number)
1412
- ], FsFormMaxDirective.prototype, "fsFormMax", void 0);
1413
- __decorate([
1414
- Input('fsFormMaxMessage'),
1415
- __metadata("design:type", String),
1416
- __metadata("design:paramtypes", [String])
1417
- ], FsFormMaxDirective.prototype, "validationMessage", null);
1418
- FsFormMaxDirective = __decorate([
1419
- Directive({
1420
- selector: '[fsFormMax]',
1421
- providers: [
1422
- VALIDATE_MESSAGE_PROVIDER
1423
- ],
1424
- })
1425
- ], FsFormMaxDirective);
1426
- return FsFormMaxDirective;
1427
- }(FsControlDirective));
1428
-
1429
- var FsFormMinLengthDirective = /** @class */ (function (_super) {
1430
- __extends(FsFormMinLengthDirective, _super);
1431
- function FsFormMinLengthDirective() {
1432
- return _super !== null && _super.apply(this, arguments) || this;
1433
- }
1434
- Object.defineProperty(FsFormMinLengthDirective.prototype, "validationMessage", {
1435
- set: function (value) {
1436
- this._validateMessages.minlength = value;
1437
- },
1438
- enumerable: true,
1439
- configurable: true
1440
- });
1441
- FsFormMinLengthDirective.prototype.ngOnChanges = function () {
1442
- this._control.updateValueAndValidity();
1443
- };
1444
- FsFormMinLengthDirective.prototype.validate = function (control) {
1445
- return Validators.minLength(this.fsFormMinLength)(this._control);
1446
- };
1447
- __decorate([
1448
- Input(),
1449
- __metadata("design:type", Number)
1450
- ], FsFormMinLengthDirective.prototype, "fsFormMinLength", void 0);
1451
- __decorate([
1452
- Input('fsFormMinLengthMessage'),
1453
- __metadata("design:type", String),
1454
- __metadata("design:paramtypes", [String])
1455
- ], FsFormMinLengthDirective.prototype, "validationMessage", null);
1456
- FsFormMinLengthDirective = __decorate([
1457
- Directive({
1458
- selector: '[fsFormMinLength]',
1459
- providers: [
1460
- VALIDATE_MESSAGE_PROVIDER
1461
- ],
1462
- })
1463
- ], FsFormMinLengthDirective);
1464
- return FsFormMinLengthDirective;
1465
- }(FsControlDirective));
1466
-
1467
- var FsFormMaxLengthDirective = /** @class */ (function (_super) {
1468
- __extends(FsFormMaxLengthDirective, _super);
1469
- function FsFormMaxLengthDirective() {
1470
- return _super !== null && _super.apply(this, arguments) || this;
1471
- }
1472
- Object.defineProperty(FsFormMaxLengthDirective.prototype, "validationMessage", {
1473
- set: function (value) {
1474
- this._validateMessages.maxlength = value;
1475
- },
1476
- enumerable: true,
1477
- configurable: true
1478
- });
1479
- FsFormMaxLengthDirective.prototype.ngOnChanges = function () {
1480
- this._control.updateValueAndValidity();
1481
- };
1482
- FsFormMaxLengthDirective.prototype.validate = function (control) {
1483
- return Validators.maxLength(this.fsFormMaxLength)(this._control);
1484
- };
1485
- __decorate([
1486
- Input(),
1487
- __metadata("design:type", Number)
1488
- ], FsFormMaxLengthDirective.prototype, "fsFormMaxLength", void 0);
1489
- __decorate([
1490
- Input('fsFormMaxLengthMessage'),
1491
- __metadata("design:type", String),
1492
- __metadata("design:paramtypes", [String])
1493
- ], FsFormMaxLengthDirective.prototype, "validationMessage", null);
1494
- FsFormMaxLengthDirective = __decorate([
1495
- Directive({
1496
- selector: '[fsFormMaxLength]',
1497
- providers: [
1498
- VALIDATE_MESSAGE_PROVIDER
1499
- ],
1500
- })
1501
- ], FsFormMaxLengthDirective);
1502
- return FsFormMaxLengthDirective;
1503
- }(FsControlDirective));
1504
-
1505
- var FsFormEmailDirective = /** @class */ (function (_super) {
1506
- __extends(FsFormEmailDirective, _super);
1507
- function FsFormEmailDirective() {
1508
- return _super !== null && _super.apply(this, arguments) || this;
1509
- }
1510
- Object.defineProperty(FsFormEmailDirective.prototype, "validationMessage", {
1511
- set: function (value) {
1512
- this._validateMessages.email = value;
1513
- },
1514
- enumerable: true,
1515
- configurable: true
1516
- });
1517
- FsFormEmailDirective.prototype.ngOnChanges = function () {
1518
- this._control.updateValueAndValidity();
1519
- };
1520
- FsFormEmailDirective.prototype.validate = function (control) {
1521
- if (isEnabled(this.fsFormEmail)) {
1522
- return FsValidators.email(this._control);
1523
- }
1524
- else {
1525
- return null;
1526
- }
1527
- };
1528
- __decorate([
1529
- Input(),
1530
- __metadata("design:type", Object)
1531
- ], FsFormEmailDirective.prototype, "fsFormEmail", void 0);
1532
- __decorate([
1533
- Input('fsFormEmailMessage'),
1534
- __metadata("design:type", String),
1535
- __metadata("design:paramtypes", [String])
1536
- ], FsFormEmailDirective.prototype, "validationMessage", null);
1537
- FsFormEmailDirective = __decorate([
1538
- Directive({
1539
- selector: '[fsFormEmail]',
1540
- providers: [
1541
- VALIDATE_MESSAGE_PROVIDER
1542
- ],
1543
- })
1544
- ], FsFormEmailDirective);
1545
- return FsFormEmailDirective;
1546
- }(FsControlDirective));
1547
-
1548
- var FsFormEmailsDirective = /** @class */ (function (_super) {
1549
- __extends(FsFormEmailsDirective, _super);
1550
- function FsFormEmailsDirective() {
1551
- return _super !== null && _super.apply(this, arguments) || this;
1552
- }
1553
- Object.defineProperty(FsFormEmailsDirective.prototype, "validationMessage", {
1554
- set: function (value) {
1555
- this._validateMessages.emails = value;
1556
- },
1557
- enumerable: true,
1558
- configurable: true
1559
- });
1560
- FsFormEmailsDirective.prototype.ngOnChanges = function () {
1561
- this._control.updateValueAndValidity();
1562
- };
1563
- FsFormEmailsDirective.prototype.validate = function (control) {
1564
- if (isEnabled(this.fsFormEmails)) {
1565
- return FsValidators.emails(this._control);
1566
- }
1567
- else {
1568
- return null;
1569
- }
1570
- };
1571
- __decorate([
1572
- Input(),
1573
- __metadata("design:type", Object)
1574
- ], FsFormEmailsDirective.prototype, "fsFormEmails", void 0);
1575
- __decorate([
1576
- Input('fsFormEmailsMessage'),
1577
- __metadata("design:type", String),
1578
- __metadata("design:paramtypes", [String])
1579
- ], FsFormEmailsDirective.prototype, "validationMessage", null);
1580
- FsFormEmailsDirective = __decorate([
1581
- Directive({
1582
- selector: '[fsFormEmails]',
1583
- providers: [
1584
- VALIDATE_MESSAGE_PROVIDER
1585
- ],
1586
- })
1587
- ], FsFormEmailsDirective);
1588
- return FsFormEmailsDirective;
1589
- }(FsControlDirective));
1590
-
1591
- var FsFormPhoneDirective = /** @class */ (function (_super) {
1592
- __extends(FsFormPhoneDirective, _super);
1593
- function FsFormPhoneDirective() {
1594
- return _super !== null && _super.apply(this, arguments) || this;
1595
- }
1596
- Object.defineProperty(FsFormPhoneDirective.prototype, "validationMessage", {
1597
- set: function (value) {
1598
- this._validateMessages.phone = value;
1599
- },
1600
- enumerable: true,
1601
- configurable: true
1602
- });
1603
- FsFormPhoneDirective.prototype.ngOnChanges = function () {
1604
- this._control.updateValueAndValidity();
1605
- };
1606
- FsFormPhoneDirective.prototype.validate = function (control) {
1607
- if (isEnabled(this.fsFormPhone)) {
1608
- return FsValidators.phone(this._control);
1609
- }
1610
- else {
1611
- return null;
1612
- }
1613
- };
1614
- __decorate([
1615
- Input(),
1616
- __metadata("design:type", Object)
1617
- ], FsFormPhoneDirective.prototype, "fsFormPhone", void 0);
1618
- __decorate([
1619
- Input('fsFormPhoneMessage'),
1620
- __metadata("design:type", String),
1621
- __metadata("design:paramtypes", [String])
1622
- ], FsFormPhoneDirective.prototype, "validationMessage", null);
1623
- FsFormPhoneDirective = __decorate([
1624
- Directive({
1625
- selector: '[fsFormPhone]',
1626
- providers: [
1627
- VALIDATE_MESSAGE_PROVIDER
1628
- ],
1629
- })
1630
- ], FsFormPhoneDirective);
1631
- return FsFormPhoneDirective;
1632
- }(FsControlDirective));
1633
-
1634
- var FsFormCompareDirective = /** @class */ (function (_super) {
1635
- __extends(FsFormCompareDirective, _super);
1636
- function FsFormCompareDirective() {
1637
- return _super !== null && _super.apply(this, arguments) || this;
1638
- }
1639
- Object.defineProperty(FsFormCompareDirective.prototype, "validationMessage", {
1640
- set: function (value) {
1641
- this._validateMessages.compare = value;
1642
- },
1643
- enumerable: true,
1644
- configurable: true
1645
- });
1646
- FsFormCompareDirective.prototype.ngOnChanges = function () {
1647
- this._control.updateValueAndValidity();
1648
- };
1649
- FsFormCompareDirective.prototype.validate = function (control) {
1650
- if (this.fsFormCompare.value === this.elementRef.nativeElement.value) {
1651
- return null;
1652
- }
1653
- else {
1654
- return { compare: true };
1655
- }
1656
- };
1657
- FsFormCompareDirective.prototype.ngAfterViewInit = function () {
1658
- var _this = this;
1659
- this.fsFormCompare.addEventListener('keyup', function () {
1660
- _this._control.updateValueAndValidity();
1661
- }, false);
1662
- };
1663
- FsFormCompareDirective.prototype.ngOnDestroy = function () {
1664
- var _this = this;
1665
- this.fsFormCompare.removeEventListener('keyup', function () {
1666
- _this._control.updateValueAndValidity();
1667
- }, false);
1668
- };
1669
- __decorate([
1670
- Input(),
1671
- __metadata("design:type", Object)
1672
- ], FsFormCompareDirective.prototype, "fsFormCompare", void 0);
1673
- __decorate([
1674
- Input('fsFormCompareMessage'),
1675
- __metadata("design:type", String),
1676
- __metadata("design:paramtypes", [String])
1677
- ], FsFormCompareDirective.prototype, "validationMessage", null);
1678
- FsFormCompareDirective = __decorate([
1679
- Directive({
1680
- selector: '[fsFormCompare]',
1681
- providers: [
1682
- VALIDATE_MESSAGE_PROVIDER,
1683
- ],
1684
- })
1685
- ], FsFormCompareDirective);
1686
- return FsFormCompareDirective;
1687
- }(FsControlDirective));
1688
-
1689
- var FsFormIntegerDirective = /** @class */ (function (_super) {
1690
- __extends(FsFormIntegerDirective, _super);
1691
- function FsFormIntegerDirective() {
1692
- return _super !== null && _super.apply(this, arguments) || this;
1693
- }
1694
- Object.defineProperty(FsFormIntegerDirective.prototype, "validationMessage", {
1695
- set: function (value) {
1696
- this._validateMessages.integer = value;
1697
- },
1698
- enumerable: true,
1699
- configurable: true
1700
- });
1701
- FsFormIntegerDirective.prototype.ngOnChanges = function () {
1702
- this._control.updateValueAndValidity();
1703
- };
1704
- FsFormIntegerDirective.prototype.validate = function (control) {
1705
- if (isEnabled(this.fsFormInteger)) {
1706
- return FsValidators.integer(this._control);
1707
- }
1708
- else {
1709
- return null;
1710
- }
1711
- };
1712
- __decorate([
1713
- Input(),
1714
- __metadata("design:type", Object)
1715
- ], FsFormIntegerDirective.prototype, "fsFormInteger", void 0);
1716
- __decorate([
1717
- Input('fsFormIntegerMessage'),
1718
- __metadata("design:type", String),
1719
- __metadata("design:paramtypes", [String])
1720
- ], FsFormIntegerDirective.prototype, "validationMessage", null);
1721
- FsFormIntegerDirective = __decorate([
1722
- Directive({
1723
- selector: '[fsFormInteger]',
1724
- providers: [
1725
- VALIDATE_MESSAGE_PROVIDER
1726
- ],
1727
- })
1728
- ], FsFormIntegerDirective);
1729
- return FsFormIntegerDirective;
1730
- }(FsControlDirective));
1731
-
1732
- var FsFormNumericDirective = /** @class */ (function (_super) {
1733
- __extends(FsFormNumericDirective, _super);
1734
- function FsFormNumericDirective() {
1735
- return _super !== null && _super.apply(this, arguments) || this;
1736
- }
1737
- Object.defineProperty(FsFormNumericDirective.prototype, "validationMessage", {
1738
- set: function (value) {
1739
- this._validateMessages.numeric = value;
1740
- },
1741
- enumerable: true,
1742
- configurable: true
1743
- });
1744
- FsFormNumericDirective.prototype.ngOnChanges = function () {
1745
- this._control.updateValueAndValidity();
1746
- };
1747
- FsFormNumericDirective.prototype.validate = function (control) {
1748
- if (isEnabled(this.fsFormNumeric)) {
1749
- return FsValidators.numeric(this._control);
1750
- }
1751
- else {
1752
- return null;
1753
- }
1754
- };
1755
- __decorate([
1756
- Input(),
1757
- __metadata("design:type", Object)
1758
- ], FsFormNumericDirective.prototype, "fsFormNumeric", void 0);
1759
- __decorate([
1760
- Input('fsFormNumericMessage'),
1761
- __metadata("design:type", String),
1762
- __metadata("design:paramtypes", [String])
1763
- ], FsFormNumericDirective.prototype, "validationMessage", null);
1764
- FsFormNumericDirective = __decorate([
1765
- Directive({
1766
- selector: '[fsFormNumeric]',
1767
- providers: [
1768
- VALIDATE_MESSAGE_PROVIDER
1769
- ],
1770
- })
1771
- ], FsFormNumericDirective);
1772
- return FsFormNumericDirective;
1773
- }(FsControlDirective));
1774
-
1775
- var FsFormPatternDirective = /** @class */ (function (_super) {
1776
- __extends(FsFormPatternDirective, _super);
1777
- function FsFormPatternDirective() {
1778
- return _super !== null && _super.apply(this, arguments) || this;
1779
- }
1780
- Object.defineProperty(FsFormPatternDirective.prototype, "validationMessage", {
1781
- set: function (value) {
1782
- this._validateMessages.pattern = value;
1783
- },
1784
- enumerable: true,
1785
- configurable: true
1786
- });
1787
- FsFormPatternDirective.prototype.ngOnChanges = function () {
1788
- this._control.updateValueAndValidity();
1789
- };
1790
- FsFormPatternDirective.prototype.validate = function (control) {
1791
- return Validators.pattern(this.fsFormPattern)(this._control);
1792
- };
1793
- __decorate([
1794
- Input(),
1795
- __metadata("design:type", RegExp)
1796
- ], FsFormPatternDirective.prototype, "fsFormPattern", void 0);
1797
- __decorate([
1798
- Input('fsFormPatternMessage'),
1799
- __metadata("design:type", String),
1800
- __metadata("design:paramtypes", [String])
1801
- ], FsFormPatternDirective.prototype, "validationMessage", null);
1802
- FsFormPatternDirective = __decorate([
1803
- Directive({
1804
- selector: '[fsFormPattern]',
1805
- providers: [
1806
- VALIDATE_MESSAGE_PROVIDER
1807
- ],
1808
- })
1809
- ], FsFormPatternDirective);
1810
- return FsFormPatternDirective;
1811
- }(FsControlDirective));
1812
-
1813
- var FsFormFunctionDirective = /** @class */ (function (_super) {
1814
- __extends(FsFormFunctionDirective, _super);
1815
- function FsFormFunctionDirective() {
1816
- return _super !== null && _super.apply(this, arguments) || this;
1817
- }
1818
- FsFormFunctionDirective.prototype.ngOnChanges = function () {
1819
- this._control.updateValueAndValidity();
1820
- };
1821
- FsFormFunctionDirective.prototype.validateAsync = function (control) {
1822
- return FsValidators.func(this._control, this.fsFormFunction, this.fsFormFunctionData);
1823
- };
1824
- __decorate([
1825
- Input(),
1826
- __metadata("design:type", Object)
1827
- ], FsFormFunctionDirective.prototype, "fsFormFunction", void 0);
1828
- __decorate([
1829
- Input(),
1830
- __metadata("design:type", Object)
1831
- ], FsFormFunctionDirective.prototype, "fsFormFunctionData", void 0);
1832
- FsFormFunctionDirective = __decorate([
1833
- Directive({
1834
- selector: '[fsFormFunction]',
1835
- providers: [
1836
- VALIDATE_MESSAGE_PROVIDER
1837
- ],
1838
- })
1839
- ], FsFormFunctionDirective);
1840
- return FsFormFunctionDirective;
1841
- }(FsControlDirective));
1842
-
1843
- var FsFormGreaterDirective = /** @class */ (function (_super) {
1844
- __extends(FsFormGreaterDirective, _super);
1845
- function FsFormGreaterDirective() {
1846
- return _super !== null && _super.apply(this, arguments) || this;
1847
- }
1848
- Object.defineProperty(FsFormGreaterDirective.prototype, "validationMessage", {
1849
- set: function (value) {
1850
- this._validateMessages.greater = value;
1851
- },
1852
- enumerable: true,
1853
- configurable: true
1854
- });
1855
- FsFormGreaterDirective.prototype.ngOnChanges = function () {
1856
- this._control.updateValueAndValidity();
1857
- };
1858
- FsFormGreaterDirective.prototype.validate = function (control) {
1859
- var greater = parseFloat(this.fsFormGreater);
1860
- var value = parseFloat(this._control.value);
1861
- if (!isNaN(greater) && !isNaN(value) && value <= greater) {
1862
- return { greater: { greater: greater, actual: value } };
1863
- }
1864
- return FsValidators.numeric(this._control);
1865
- };
1866
- __decorate([
1867
- Input(),
1868
- __metadata("design:type", Object)
1869
- ], FsFormGreaterDirective.prototype, "fsFormGreater", void 0);
1870
- __decorate([
1871
- Input('fsFormGreaterMessage'),
1872
- __metadata("design:type", String),
1873
- __metadata("design:paramtypes", [String])
1874
- ], FsFormGreaterDirective.prototype, "validationMessage", null);
1875
- FsFormGreaterDirective = __decorate([
1876
- Directive({
1877
- selector: '[fsFormGreater]',
1878
- providers: [
1879
- VALIDATE_MESSAGE_PROVIDER
1880
- ],
1881
- })
1882
- ], FsFormGreaterDirective);
1883
- return FsFormGreaterDirective;
1884
- }(FsControlDirective));
1885
-
1886
- var FsFormDateRangeDirective = /** @class */ (function (_super) {
1887
- __extends(FsFormDateRangeDirective, _super);
1888
- function FsFormDateRangeDirective() {
1889
- return _super !== null && _super.apply(this, arguments) || this;
1890
- }
1891
- Object.defineProperty(FsFormDateRangeDirective.prototype, "validationMessage", {
1892
- set: function (value) {
1893
- this._validateMessages.dateRange = value;
1894
- },
1895
- enumerable: true,
1896
- configurable: true
1897
- });
1898
- FsFormDateRangeDirective.prototype.ngOnChanges = function () {
1899
- this._control.updateValueAndValidity();
1900
- };
1901
- FsFormDateRangeDirective.prototype.validate = function (control) {
1902
- if (isEnabled(this.fsFormDateRange)) {
1903
- return FsValidators.dateRange(this._control);
1904
- }
1905
- else {
1906
- return null;
1907
- }
1908
- };
1909
- __decorate([
1910
- Input(),
1911
- __metadata("design:type", Object)
1912
- ], FsFormDateRangeDirective.prototype, "fsFormDateRange", void 0);
1913
- __decorate([
1914
- Input('fsFormDateRangeMessage'),
1915
- __metadata("design:type", String),
1916
- __metadata("design:paramtypes", [String])
1917
- ], FsFormDateRangeDirective.prototype, "validationMessage", null);
1918
- FsFormDateRangeDirective = __decorate([
1919
- Directive({
1920
- selector: '[fsFormDateRange]',
1921
- providers: [
1922
- VALIDATE_MESSAGE_PROVIDER
1923
- ],
1924
- })
1925
- ], FsFormDateRangeDirective);
1926
- return FsFormDateRangeDirective;
1927
- }(FsControlDirective));
1928
-
1929
- var FsFormLesserDirective = /** @class */ (function (_super) {
1930
- __extends(FsFormLesserDirective, _super);
1931
- function FsFormLesserDirective() {
1932
- return _super !== null && _super.apply(this, arguments) || this;
1933
- }
1934
- Object.defineProperty(FsFormLesserDirective.prototype, "validationMessage", {
1935
- set: function (value) {
1936
- this._validateMessages.lesser = value;
1937
- },
1938
- enumerable: true,
1939
- configurable: true
1940
- });
1941
- FsFormLesserDirective.prototype.ngOnChanges = function () {
1942
- this._control.updateValueAndValidity();
1943
- };
1944
- FsFormLesserDirective.prototype.validate = function (control) {
1945
- var lesser = parseFloat(this.fsFormLesser);
1946
- var value = parseFloat(this._control.value);
1947
- if (!isNaN(lesser) && !isNaN(value) && value >= lesser) {
1948
- return { lesser: { lesser: lesser, actual: value } };
1949
- }
1950
- return FsValidators.numeric(this._control);
1951
- };
1952
- __decorate([
1953
- Input(),
1954
- __metadata("design:type", Object)
1955
- ], FsFormLesserDirective.prototype, "fsFormLesser", void 0);
1956
- __decorate([
1957
- Input('fsFormLesserMessage'),
1958
- __metadata("design:type", String),
1959
- __metadata("design:paramtypes", [String])
1960
- ], FsFormLesserDirective.prototype, "validationMessage", null);
1961
- FsFormLesserDirective = __decorate([
1962
- Directive({
1963
- selector: '[fsFormLesser]',
1964
- providers: [
1965
- VALIDATE_MESSAGE_PROVIDER
1966
- ],
1967
- })
1968
- ], FsFormLesserDirective);
1969
- return FsFormLesserDirective;
1970
- }(FsControlDirective));
1971
-
1972
- var FsFormUrlDirective = /** @class */ (function (_super) {
1973
- __extends(FsFormUrlDirective, _super);
1974
- function FsFormUrlDirective() {
1975
- var _this = _super !== null && _super.apply(this, arguments) || this;
1976
- _this.fsFormUrlProtocol = false;
1977
- return _this;
1978
- }
1979
- Object.defineProperty(FsFormUrlDirective.prototype, "validationMessage", {
1980
- set: function (value) {
1981
- this._validateMessages.url = value;
1982
- },
1983
- enumerable: true,
1984
- configurable: true
1985
- });
1986
- FsFormUrlDirective.prototype.ngOnChanges = function () {
1987
- this._control.updateValueAndValidity();
1988
- };
1989
- FsFormUrlDirective.prototype.validate = function (control) {
1990
- if (isEnabled(this.fsFormUrl)) {
1991
- return FsValidators.url(this._control, this.fsFormUrlProtocol);
1992
- }
1993
- else {
1994
- return null;
1995
- }
1996
- };
1997
- __decorate([
1998
- Input(),
1999
- __metadata("design:type", Object)
2000
- ], FsFormUrlDirective.prototype, "fsFormUrl", void 0);
2001
- __decorate([
2002
- Input(),
2003
- __metadata("design:type", Object)
2004
- ], FsFormUrlDirective.prototype, "fsFormUrlProtocol", void 0);
2005
- __decorate([
2006
- Input('fsFormUrlMessage'),
2007
- __metadata("design:type", String),
2008
- __metadata("design:paramtypes", [String])
2009
- ], FsFormUrlDirective.prototype, "validationMessage", null);
2010
- FsFormUrlDirective = __decorate([
2011
- Directive({
2012
- selector: '[fsFormUrl]',
2013
- providers: [
2014
- VALIDATE_MESSAGE_PROVIDER
2015
- ],
2016
- })
2017
- ], FsFormUrlDirective);
2018
- return FsFormUrlDirective;
2019
- }(FsControlDirective));
2020
-
2021
- var FsSubmitButtonDirective = /** @class */ (function () {
2022
- function FsSubmitButtonDirective(_matButton, _form, _elementRef, _cdRef) {
2023
- this._matButton = _matButton;
2024
- this._form = _form;
2025
- this._elementRef = _elementRef;
2026
- this._cdRef = _cdRef;
2027
- this.dirtySubmit = true;
2028
- this.transitionStyle = null;
2029
- this.active = false;
2030
- this._destroy$ = new Subject();
2031
- }
2032
- FsSubmitButtonDirective.prototype.ngOnInit = function () {
2033
- var _this = this;
2034
- if (this._form) {
2035
- this._form.addSubmitButton(this);
2036
- fromEvent(this.element, 'click')
2037
- .pipe(takeUntil(this._destroy$))
2038
- .subscribe(function () {
2039
- _this.active = true;
2040
- });
2041
- if (this.dirtySubmit) {
2042
- if (this._form.dirtySubmitButton) {
2043
- if (!this._form.ngForm.dirty) {
2044
- this.disable();
2045
- }
2046
- }
2047
- }
2048
- this.transitionStyle = 'none';
2049
- setTimeout(function () {
2050
- _this.transitionStyle = null;
2051
- }, 500);
2052
- }
2053
- };
2054
- FsSubmitButtonDirective.prototype.disable = function () {
2055
- if (this._matButton) {
2056
- this._matButton.disabled = true;
2057
- this._cdRef.markForCheck();
2058
- }
2059
- };
2060
- FsSubmitButtonDirective.prototype.enable = function () {
2061
- if (this._matButton) {
2062
- this._matButton.disabled = false;
2063
- this._matButton.disableRipple = true;
2064
- this._cdRef.markForCheck();
2065
- }
2066
- };
2067
- FsSubmitButtonDirective.prototype.process = function () {
2068
- this.setClass('process');
2069
- this._matButton.disableRipple = true;
2070
- };
2071
- FsSubmitButtonDirective.prototype.success = function () {
2072
- this.setClass('success');
2073
- this._matButton.disableRipple = false;
2074
- };
2075
- FsSubmitButtonDirective.prototype.error = function () {
2076
- this.setClass('error');
2077
- this._matButton.disableRipple = false;
2078
- };
2079
- FsSubmitButtonDirective.prototype.setClass = function (cls) {
2080
- var svg = this._getSvg(cls);
2081
- this._resetClass();
2082
- this._disableShadowAnimation();
2083
- this.element.classList.add("submit-" + cls);
2084
- this.element.append(svg);
2085
- };
2086
- Object.defineProperty(FsSubmitButtonDirective.prototype, "element", {
2087
- get: function () {
2088
- return this._elementRef.nativeElement;
2089
- },
2090
- enumerable: true,
2091
- configurable: true
2092
- });
2093
- FsSubmitButtonDirective.prototype.reset = function () {
2094
- this.active = false;
2095
- this.enable();
2096
- this.element.querySelectorAll('.svg-icon')
2097
- .forEach(function (el) {
2098
- el.remove();
2099
- });
2100
- this._matButton.disableRipple = false;
2101
- this._resetClass();
2102
- };
2103
- FsSubmitButtonDirective.prototype.ngOnDestroy = function () {
2104
- this._destroy$.next();
2105
- this._destroy$.complete();
2106
- this._form.removeSubmitButton(this);
2107
- };
2108
- FsSubmitButtonDirective.prototype._disableShadowAnimation = function () {
2109
- // .mat-elevation-z2 removes the click shadow animation
2110
- //this.element.classList.add('mat-elevation-z2');
2111
- };
2112
- FsSubmitButtonDirective.prototype._resetClass = function () {
2113
- this.element.classList.remove('submit-success', 'submit-error', 'submit-process', 'mat-elevation-z2');
2114
- };
2115
- FsSubmitButtonDirective.prototype._getSvg = function (type) {
2116
- if (type === 'success') {
2117
- return new DOMParser().parseFromString("<svg class=\"svg-icon svg-icon-success\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" version=\"1.1\" x=\"0px\" y=\"0px\" viewBox=\"0 0 38 38\" style=\"enable-background:new 0 0 38 38;\" xml:space=\"preserve\" width=\"38px\" height=\"38px\">\n <g>\n <g class=\"check\">\n <g>\n <path d=\"M29.6,11.9c-0.5-0.5-1.3-0.5-1.8,0L16.3,23.4l-6.1-6.1c-0.5-0.5-1.3-0.5-1.8,0s-0.5,1.3,0,1.8l7,7c0.3,0.3,0.6,0.4,0.9,0.4s0.7-0.1,0.9-0.4l12.4-12.4C30.1,13.2,30.1,12.4,29.6,11.9z\"/>\n </g>\n </g>\n </g>\n </svg>", 'text/xml').firstChild;
2118
- }
2119
- if (type === 'process') {
2120
- return new DOMParser().parseFromString("<svg class=\"svg-icon svg-icon-process\" width=\"38\" height=\"38\" viewBox=\"0 0 38 38\" xmlns=\"http://www.w3.org/2000/svg\">\n <g fill=\"none\" fill-rule=\"evenodd\">\n <g transform=\"translate(1 1)\" stroke-width=\"2\"><circle stroke-opacity=\".5\" cx=\"18\" cy=\"18\" r=\"18\"/>\n <path d=\"M36 18c0-9.94-8.06-18-18-18\"><animateTransform attributeName=\"transform\" type=\"rotate\" from=\"0 18 18\" to=\"360 18 18\" dur=\".7s\" repeatCount=\"indefinite\"/></path>\n </g>\n </g>\n </svg>", 'text/xml').firstChild;
2121
- }
2122
- if (type === 'error') {
2123
- return new DOMParser().parseFromString("<svg class=\"svg-icon svg-icon-error\" xmlns=\"http://www.w3.org/2000/svg\" width=\"38px\" height=\"38px\" viewBox=\"0 0 16 16\"><g><path d=\"M8 1c3.9 0 7 3.1 7 7s-3.1 7-7 7-7-3.1-7-7 3.1-7 7-7zM8 0c-4.4 0-8 3.6-8 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8v0z\" data-original=\"#444444\" data-old_color=\"#444444\"/><path d=\"M12.2 10.8l-2.8-2.8 2.8-2.8-1.4-1.4-2.8 2.8-2.8-2.8-1.4 1.4 2.8 2.8-2.8 2.8 1.4 1.4 2.8-2.8 2.8 2.8z\"/></g> </svg>", 'text/xml').firstChild;
2124
- }
2125
- };
2126
- FsSubmitButtonDirective.ctorParameters = function () { return [
2127
- { type: MatButton, decorators: [{ type: Optional }, { type: Host }] },
2128
- { type: FsFormDirective, decorators: [{ type: Optional }] },
2129
- { type: ElementRef },
2130
- { type: ChangeDetectorRef }
2131
- ]; };
2132
- __decorate([
2133
- Input(),
2134
- __metadata("design:type", Object)
2135
- ], FsSubmitButtonDirective.prototype, "name", void 0);
2136
- __decorate([
2137
- Input(),
2138
- __metadata("design:type", Object)
2139
- ], FsSubmitButtonDirective.prototype, "dirtySubmit", void 0);
2140
- __decorate([
2141
- HostBinding('style.transition'),
2142
- __metadata("design:type", Object)
2143
- ], FsSubmitButtonDirective.prototype, "transitionStyle", void 0);
2144
- FsSubmitButtonDirective = __decorate([
2145
- Directive({
2146
- selector: 'button[type="submit"]',
2147
- }),
2148
- __param(0, Optional()), __param(0, Host()),
2149
- __param(1, Optional()),
2150
- __metadata("design:paramtypes", [MatButton,
2151
- FsFormDirective,
2152
- ElementRef,
2153
- ChangeDetectorRef])
2154
- ], FsSubmitButtonDirective);
2155
- return FsSubmitButtonDirective;
2156
- }());
2157
-
2158
- var FsFormValidateDirective = /** @class */ (function (_super) {
2159
- __extends(FsFormValidateDirective, _super);
2160
- function FsFormValidateDirective() {
2161
- return _super !== null && _super.apply(this, arguments) || this;
2162
- }
2163
- FsFormValidateDirective.prototype.ngOnChanges = function () {
2164
- this._control.updateValueAndValidity();
2165
- };
2166
- FsFormValidateDirective.prototype.validateAsync = function (control) {
2167
- return FsValidators.func(this._control, this.validateFn, this.validateFnData);
2168
- };
2169
- __decorate([
2170
- Input('validate'),
2171
- __metadata("design:type", Object)
2172
- ], FsFormValidateDirective.prototype, "validateFn", void 0);
2173
- __decorate([
2174
- Input('validateData'),
2175
- __metadata("design:type", Object)
2176
- ], FsFormValidateDirective.prototype, "validateFnData", void 0);
2177
- FsFormValidateDirective = __decorate([
2178
- Directive({
2179
- selector: '[validate]',
2180
- providers: [
2181
- VALIDATE_MESSAGE_PROVIDER
2182
- ],
2183
- })
2184
- ], FsFormValidateDirective);
2185
- return FsFormValidateDirective;
2186
- }(FsControlDirective));
2187
-
2188
- var FsFormDialogActionsComponent = /** @class */ (function () {
2189
- function FsFormDialogActionsComponent(_form, _dialogRef, _cdRef) {
2190
- this._form = _form;
2191
- this._dialogRef = _dialogRef;
2192
- this._cdRef = _cdRef;
2193
- this.save = true;
2194
- this.create = false;
2195
- this.close = false;
2196
- this.dirty = false;
2197
- this._destroy$ = new Subject();
2198
- }
2199
- FsFormDialogActionsComponent.prototype.ngOnInit = function () {
2200
- var _this = this;
2201
- if (this._form) {
2202
- this._form.ngForm.valueChanges
2203
- .pipe(filter(function () { return (!_this.dirty); }), takeUntil(this._destroy$))
2204
- .subscribe(function () {
2205
- _this.dirty = _this._form.ngForm.dirty;
2206
- _this._cdRef.markForCheck();
2207
- });
2208
- this._form.submitted
2209
- .pipe(delay(50), takeUntil(this._destroy$))
2210
- .subscribe(function () {
2211
- _this.dirty = false;
2212
- _this._cdRef.markForCheck();
2213
- });
2214
- this._form.reseted
2215
- .pipe(takeUntil(this._destroy$))
2216
- .subscribe(function () {
2217
- _this.dirty = false;
2218
- _this._cdRef.markForCheck();
2219
- });
2220
- }
2221
- };
2222
- FsFormDialogActionsComponent.prototype.closeClick = function () {
2223
- var _this = this;
2224
- if (this._form) {
2225
- this._form.triggerConfirm()
2226
- .pipe(filter(function (confirmResult) { return (confirmResult !== ConfirmResult.Review); }), takeUntil(this._destroy$))
2227
- .subscribe(function () {
2228
- _this._dialogRef.close(null);
2229
- });
2230
- }
2231
- else {
2232
- this._dialogRef.close(null);
2233
- }
2234
- };
2235
- FsFormDialogActionsComponent.prototype.ngOnDestroy = function () {
2236
- this._destroy$.next();
2237
- this._destroy$.complete();
2238
- };
2239
- FsFormDialogActionsComponent.ctorParameters = function () { return [
2240
- { type: FsFormDirective, decorators: [{ type: Optional }] },
2241
- { type: MatDialogRef, decorators: [{ type: Optional }] },
2242
- { type: ChangeDetectorRef }
2243
- ]; };
2244
- __decorate([
2245
- Input(),
2246
- __metadata("design:type", Object)
2247
- ], FsFormDialogActionsComponent.prototype, "save", void 0);
2248
- __decorate([
2249
- Input(),
2250
- __metadata("design:type", Object)
2251
- ], FsFormDialogActionsComponent.prototype, "create", void 0);
2252
- __decorate([
2253
- Input(),
2254
- __metadata("design:type", Object)
2255
- ], FsFormDialogActionsComponent.prototype, "close", void 0);
2256
- __decorate([
2257
- Input(),
2258
- __metadata("design:type", String)
2259
- ], FsFormDialogActionsComponent.prototype, "name", void 0);
2260
- FsFormDialogActionsComponent = __decorate([
2261
- Component({
2262
- selector: 'fs-form-dialog-actions',
2263
- template: "<div class=\"buttons\">\r\n <ng-container *ngIf=\"save\">\r\n <button \r\n mat-button \r\n type=\"submit\"\r\n color=\"primary\" \r\n [name]=\"name\">\r\n {{create ? 'Create' : 'Save'}}\r\n </button>\r\n <button \r\n mat-button \r\n type=\"button\"\r\n [disabled]=\"close && !dirty && !create\"\r\n [matDialogClose]=\"null\">\r\n Cancel\r\n </button>\r\n </ng-container>\r\n\r\n <ng-content></ng-content>\r\n <div class=\"close\" *ngIf=\"close\">\r\n <button \r\n mat-button \r\n type=\"button\"\r\n [color]=\"dirty ? 'basic' : 'primary'\"\r\n (click)=\"closeClick()\">\r\n Close\r\n </button>\r\n </div>\r\n</div>",
2264
- changeDetection: ChangeDetectionStrategy.OnPush,
2265
- styles: [".buttons{display:flex;flex-grow:1;align-items:center}.buttons .close{display:flex;flex-grow:1;justify-content:flex-end}:host{display:flex;flex-grow:1}@media only screen and (max-width:599px){.buttons{flex-direction:column}}"]
2266
- }),
2267
- __param(0, Optional()),
2268
- __param(1, Optional()),
2269
- __metadata("design:paramtypes", [FsFormDirective,
2270
- MatDialogRef,
2271
- ChangeDetectorRef])
2272
- ], FsFormDialogActionsComponent);
2273
- return FsFormDialogActionsComponent;
2274
- }());
2275
-
2276
- var FsFormModule = /** @class */ (function () {
2277
- function FsFormModule() {
2278
- }
2279
- FsFormModule_1 = FsFormModule;
2280
- FsFormModule.forRoot = function () {
2281
- return {
2282
- ngModule: FsFormModule_1,
2283
- };
2284
- };
2285
- var FsFormModule_1;
2286
- FsFormModule = FsFormModule_1 = __decorate([
2287
- NgModule({
2288
- imports: [
2289
- CommonModule,
2290
- FormsModule,
2291
- MatButtonModule,
2292
- MatDialogModule,
2293
- ],
2294
- declarations: [
2295
- FsFormDirective,
2296
- FsControlDirective,
2297
- FsFormRequiredDirective,
2298
- FsFormMinDirective,
2299
- FsFormMaxDirective,
2300
- FsFormMinLengthDirective,
2301
- FsFormMaxLengthDirective,
2302
- FsFormEmailDirective,
2303
- FsFormEmailsDirective,
2304
- FsFormPhoneDirective,
2305
- FsFormCompareDirective,
2306
- FsFormIntegerDirective,
2307
- FsFormNumericDirective,
2308
- FsFormPatternDirective,
2309
- FsFormFunctionDirective,
2310
- FsFormDateRangeDirective,
2311
- FsFormGreaterDirective,
2312
- FsFormLesserDirective,
2313
- FsFormUrlDirective,
2314
- FsFormDialogCloseDirective,
2315
- FsSubmitButtonDirective,
2316
- FsFormValidateDirective,
2317
- FsFormDialogActionsComponent,
2318
- ],
2319
- exports: [
2320
- FsFormDirective,
2321
- FsControlDirective,
2322
- FsFormRequiredDirective,
2323
- FsFormMinDirective,
2324
- FsFormMaxDirective,
2325
- FsFormMinLengthDirective,
2326
- FsFormMaxLengthDirective,
2327
- FsFormEmailDirective,
2328
- FsFormEmailsDirective,
2329
- FsFormPhoneDirective,
2330
- FsFormCompareDirective,
2331
- FsFormIntegerDirective,
2332
- FsFormNumericDirective,
2333
- FsFormPatternDirective,
2334
- FsFormFunctionDirective,
2335
- FsFormDateRangeDirective,
2336
- FsFormGreaterDirective,
2337
- FsFormLesserDirective,
2338
- FsFormUrlDirective,
2339
- FsFormDialogCloseDirective,
2340
- FsSubmitButtonDirective,
2341
- FsFormValidateDirective,
2342
- FsFormDialogActionsComponent,
2343
- ],
2344
- providers: [
2345
- {
2346
- provide: ErrorStateMatcher,
2347
- useClass: ShowOnDirtyErrorStateMatcher,
2348
- },
2349
- ],
2350
- })
2351
- ], FsFormModule);
2352
- return FsFormModule;
2353
- }());
2354
-
2355
- var FormDeactivateGuard = /** @class */ (function () {
2356
- function FormDeactivateGuard(_prompt) {
2357
- this._prompt = _prompt;
2358
- }
2359
- FormDeactivateGuard.prototype.canDeactivate = function (directive) {
2360
- if (!('getForm' in directive)) {
2361
- var error = "Directive " + directive.constructor.name + " does not property implement interface FormDeactivate";
2362
- console.error(error);
2363
- return of(true);
2364
- }
2365
- var form = directive.getForm();
2366
- if (!(form instanceof FsFormDirective)) {
2367
- var error = "Directive " + directive.constructor.name + ".getForm() does not return a valid FsFormDirective";
2368
- console.error(error);
2369
- return of(true);
2370
- }
2371
- return confirmUnsaved(form, this._prompt)
2372
- .pipe(map(function (result) {
2373
- return confirmResultContinue(result);
2374
- }));
2375
- };
2376
- FormDeactivateGuard.ctorParameters = function () { return [
2377
- { type: FsPrompt }
2378
- ]; };
2379
- FormDeactivateGuard.ɵprov = ɵɵdefineInjectable({ factory: function FormDeactivateGuard_Factory() { return new FormDeactivateGuard(ɵɵinject(FsPrompt)); }, token: FormDeactivateGuard, providedIn: "root" });
2380
- FormDeactivateGuard = __decorate([
2381
- Injectable({
2382
- providedIn: 'root'
2383
- }),
2384
- __metadata("design:paramtypes", [FsPrompt])
2385
- ], FormDeactivateGuard);
2386
- return FormDeactivateGuard;
2387
- }());
2388
-
2389
- // Modules
2390
-
2391
- /**
2392
- * Generated bundle index. Do not edit.
2393
- */
2394
-
2395
- export { ConfirmResult, FormDeactivateGuard, FormStatus, FsForm, FsFormDialogActionsComponent, FsFormDirective, FsFormModule, FsValidators, FsFormDialogCloseDirective as ɵa, FsControlDirective as ɵb, VALIDATE_MESSAGES as ɵc, VALIDATE_MESSAGE_PROVIDER as ɵd, messageProviderFactory as ɵe, FsFormRequiredDirective as ɵf, FsFormMinDirective as ɵg, FsFormMaxDirective as ɵh, FsFormMinLengthDirective as ɵi, FsFormMaxLengthDirective as ɵj, FsFormEmailDirective as ɵk, FsFormEmailsDirective as ɵl, FsFormPhoneDirective as ɵm, FsFormCompareDirective as ɵn, FsFormIntegerDirective as ɵo, FsFormNumericDirective as ɵp, FsFormPatternDirective as ɵq, FsFormFunctionDirective as ɵr, FsFormDateRangeDirective as ɵs, FsFormGreaterDirective as ɵt, FsFormLesserDirective as ɵu, FsFormUrlDirective as ɵv, FsSubmitButtonDirective as ɵw, FsFormValidateDirective as ɵx };
2396
- //# sourceMappingURL=firestitch-form.js.map