@firestitch/form 9.7.6 → 12.0.1

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 +2672 -2546
  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 -668
  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 -2110
  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 -709
  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 -2399
  148. package/fesm5/firestitch-form.js.map +0 -1
  149. package/firestitch-form.metadata.json +0 -1
@@ -1,2399 +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
- else {
577
- subscriber.error();
578
- }
579
- })), defer(function () {
580
- subscriber.next();
581
- subscriber.complete();
582
- }));
583
- }), takeUntil(this._destroy$))
584
- .subscribe();
585
- }
586
- };
587
- FsFormDirective.prototype._registerConfirmTabs = function () {
588
- var _this = this;
589
- if (this.tabGroup) {
590
- this.registerConfirmTabGroup(this.tabGroup);
591
- }
592
- this.registerConfirmTabGroups(this._tabGroups.toArray());
593
- this._tabGroups.changes
594
- .pipe(takeUntil(this._destroy$))
595
- .subscribe(function () {
596
- _this.registerConfirmTabGroups(_this._tabGroups.toArray());
597
- });
598
- };
599
- FsFormDirective.prototype.registerConfirmTabGroups = function (tabGroups) {
600
- var _this = this;
601
- tabGroups.forEach(function (tabGroup) {
602
- _this.registerConfirmTabGroup(tabGroup);
603
- });
604
- };
605
- FsFormDirective.prototype.registerConfirmTabGroup = function (tabGroup) {
606
- var _this = this;
607
- var confirmTabGroup = tabGroup;
608
- if (!confirmTabGroup._originalHandleClick) {
609
- confirmTabGroup._originalHandleClick = tabGroup._handleClick;
610
- confirmTabGroup._handlClick$ = new Subject();
611
- confirmTabGroup._handleClick = function (tab, tabHeader, idx) {
612
- if (confirmTabGroup._handlClick$.observers.length) {
613
- confirmTabGroup._handlClick$.next({ tab: tab, tabHeader: tabHeader, idx: idx });
614
- }
615
- else {
616
- confirmTabGroup._originalHandleClick(tab, tabHeader, idx);
617
- }
618
- };
619
- }
620
- confirmTabGroup._handlClick$
621
- .pipe(takeUntil(this._destroy$))
622
- .subscribe(function (event) {
623
- if (!_this.submitting) {
624
- if (_this.confirm && _this.confirmTabs) {
625
- _this.triggerConfirm()
626
- .pipe(takeUntil(_this._destroy$))
627
- .subscribe(function (result) {
628
- if (confirmResultContinue(result)) {
629
- confirmTabGroup.selectedIndex = event.idx;
630
- }
631
- });
632
- }
633
- else {
634
- confirmTabGroup._originalHandleClick(event.tab, event.tabHeader, event.idx);
635
- }
636
- }
637
- });
638
- };
639
- FsFormDirective.prototype._registerConfirmDialogClose = function () {
640
- var _this = this;
641
- if (this._dialogRef) {
642
- this.formDialogClose.forEach(function (item) {
643
- _this._registerDialogClose(item);
644
- });
645
- this.formDialogClose.changes
646
- .pipe(takeUntil(this._destroy$))
647
- .subscribe(function (e) {
648
- e.forEach(function (item) {
649
- _this._registerDialogClose(item);
650
- });
651
- });
652
- }
653
- };
654
- FsFormDirective.prototype._registerConfirmDialogBackdropEscape = function () {
655
- var _this = this;
656
- this._dialogBackdropEscape = this._dialogRef && this._dialogRef.disableClose !== true;
657
- if (this._dialogRef && !this._dialogRef.disableClose) {
658
- this._dialogRef.disableClose = true;
659
- this._dialogRef.backdropClick()
660
- .pipe(takeUntil(this._destroy$))
661
- .subscribe(function () {
662
- _this._formClose();
663
- });
664
- this._destroy$
665
- .subscribe(function () {
666
- _this._dialogRef.disableClose = false;
667
- });
668
- }
669
- };
670
- FsFormDirective.prototype._registerAutocomplete = function () {
671
- var _this = this;
672
- this._registerControl = this.ngForm.form.registerControl.bind(this.ngForm.form);
673
- this.ngForm.form.registerControl = function (name, control) {
674
- var el = _this._element.nativeElement.querySelector("input[name='" + name + "']");
675
- if (el) {
676
- el.setAttribute('name', name + '_' + guid());
677
- if (!el.getAttribute('autocomplete')) {
678
- el.setAttribute('autocomplete', 'none');
679
- }
680
- }
681
- return _this._registerControl(name, control);
682
- };
683
- };
684
- FsFormDirective.prototype._registerDirtySubmitButton = function () {
685
- var _this = this;
686
- if (!this.ngForm) {
687
- return;
688
- }
689
- this.ngForm.form.valueChanges
690
- .pipe(takeUntil(this._destroy$))
691
- .subscribe(function () {
692
- _this._updateDirtySubmitButtons();
693
- });
694
- this._submitButtons.changes
695
- .pipe(takeUntil(this._destroy$))
696
- .subscribe(function () {
697
- _this._updateDirtySubmitButtons();
698
- });
699
- };
700
- FsFormDirective.prototype._updateDirtySubmitButtons = function () {
701
- var _this = this;
702
- this._submitButtons
703
- .forEach(function (submitButton) {
704
- if (!_this.confirm || !_this.dirtySubmitButton || _this.ngForm.dirty || !submitButton.dirtySubmit) {
705
- submitButton.enable();
706
- }
707
- else {
708
- submitButton.disable();
709
- }
710
- });
711
- };
712
- FsFormDirective.prototype._broadcastSubmittingEvents = function () {
713
- this._status$.next(FormStatus.Submitting);
714
- this._form.broadcast('submit', this.ngForm);
715
- };
716
- FsFormDirective.prototype._markControlsAsTouchedAndUpdateValidity = function () {
717
- Object.values(this.ngForm.controls)
718
- .forEach(function (control) {
719
- control.markAsDirty();
720
- control.markAsTouched();
721
- control.updateValueAndValidity();
722
- });
723
- };
724
- FsFormDirective.prototype._setupActiveSubmitButton = function () {
725
- this._activeSubmitButton = this._getActiveButton();
726
- this._resetButtons();
727
- if (this._activeSubmitButton) {
728
- this._activeSubmitButton.process();
729
- }
730
- };
731
- FsFormDirective.prototype._waitUntilStatusPending = function () {
732
- return this.ngForm.statusChanges
733
- .pipe(startWith(this.ngForm.status), first(function (state) { return state !== 'PENDING'; }));
734
- };
735
- FsFormDirective.prototype._handleError = function (e) {
736
- console.log('%c Form Submit ', 'color: white; background-color: #D33F49', 'Error occured');
737
- console.group('Error Details:');
738
- console.log('Message: ', e);
739
- console.log('FormRef: ', this);
740
- if (this.ngForm.invalid) {
741
- var errors = getFormErrors(this.ngForm.control, null);
742
- console.log('Validation Errors: ', errors);
743
- }
744
- console.groupEnd();
745
- this._completeSubmit(false, null);
746
- };
747
- FsFormDirective.ctorParameters = function () { return [
748
- { type: NgForm, decorators: [{ type: Inject, args: [NgForm,] }] },
749
- { type: FsForm },
750
- { type: ElementRef },
751
- { type: FsMessage },
752
- { type: FsPrompt },
753
- { type: NgZone },
754
- { type: MatDialogRef, decorators: [{ type: Optional }, { type: Inject, args: [MatDialogRef,] }] },
755
- { type: DrawerRef, decorators: [{ type: Optional }, { type: Inject, args: [DrawerRef,] }] }
756
- ]; };
757
- __decorate([
758
- Input(),
759
- __metadata("design:type", Object)
760
- ], FsFormDirective.prototype, "wrapperSelector", void 0);
761
- __decorate([
762
- Input(),
763
- __metadata("design:type", Object)
764
- ], FsFormDirective.prototype, "messageSelector", void 0);
765
- __decorate([
766
- Input(),
767
- __metadata("design:type", Object)
768
- ], FsFormDirective.prototype, "hintSelector", void 0);
769
- __decorate([
770
- Input(),
771
- __metadata("design:type", Object)
772
- ], FsFormDirective.prototype, "labelSelector", void 0);
773
- __decorate([
774
- Input(),
775
- __metadata("design:type", Object)
776
- ], FsFormDirective.prototype, "autocomplete", void 0);
777
- __decorate([
778
- Input(),
779
- __metadata("design:type", Object)
780
- ], FsFormDirective.prototype, "shortcuts", void 0);
781
- __decorate([
782
- Input(),
783
- __metadata("design:type", Object)
784
- ], FsFormDirective.prototype, "confirm", void 0);
785
- __decorate([
786
- Input(),
787
- __metadata("design:type", Object)
788
- ], FsFormDirective.prototype, "confirmDialog", void 0);
789
- __decorate([
790
- Input(),
791
- __metadata("design:type", Object)
792
- ], FsFormDirective.prototype, "confirmDrawer", void 0);
793
- __decorate([
794
- Input(),
795
- __metadata("design:type", Object)
796
- ], FsFormDirective.prototype, "confirmBrowser", void 0);
797
- __decorate([
798
- Input(),
799
- __metadata("design:type", Object)
800
- ], FsFormDirective.prototype, "confirmTabs", void 0);
801
- __decorate([
802
- Input(),
803
- __metadata("design:type", Object)
804
- ], FsFormDirective.prototype, "dirtySubmitButton", void 0);
805
- __decorate([
806
- Input(),
807
- __metadata("design:type", Function)
808
- ], FsFormDirective.prototype, "submit", void 0);
809
- __decorate([
810
- Input(),
811
- __metadata("design:type", Object)
812
- ], FsFormDirective.prototype, "successDelay", void 0);
813
- __decorate([
814
- Input(),
815
- __metadata("design:type", Object)
816
- ], FsFormDirective.prototype, "errorDelay", void 0);
817
- __decorate([
818
- Input(),
819
- __metadata("design:type", MatTabGroup)
820
- ], FsFormDirective.prototype, "tabGroup", void 0);
821
- __decorate([
822
- Output('fsForm'),
823
- __metadata("design:type", EventEmitter)
824
- ], FsFormDirective.prototype, "submitEvent", void 0);
825
- __decorate([
826
- Output(),
827
- __metadata("design:type", EventEmitter)
828
- ], FsFormDirective.prototype, "invalid", void 0);
829
- __decorate([
830
- Output(),
831
- __metadata("design:type", EventEmitter)
832
- ], FsFormDirective.prototype, "valid", void 0);
833
- __decorate([
834
- Output(),
835
- __metadata("design:type", EventEmitter)
836
- ], FsFormDirective.prototype, "submitted", void 0);
837
- __decorate([
838
- Output(),
839
- __metadata("design:type", EventEmitter)
840
- ], FsFormDirective.prototype, "reseted", void 0);
841
- __decorate([
842
- Output(),
843
- __metadata("design:type", EventEmitter)
844
- ], FsFormDirective.prototype, "cleared", void 0);
845
- __decorate([
846
- HostBinding('class.fs-form'),
847
- __metadata("design:type", Object)
848
- ], FsFormDirective.prototype, "fsformClass", void 0);
849
- __decorate([
850
- ContentChildren(FsFormDialogCloseDirective, { descendants: true }),
851
- __metadata("design:type", QueryList)
852
- ], FsFormDirective.prototype, "formDialogClose", void 0);
853
- __decorate([
854
- ContentChildren(MatTabGroup, { descendants: true }),
855
- __metadata("design:type", QueryList)
856
- ], FsFormDirective.prototype, "_tabGroups", void 0);
857
- FsFormDirective = __decorate([
858
- Directive({
859
- selector: '[fsForm]',
860
- }),
861
- __param(0, Inject(NgForm)),
862
- __param(6, Optional()), __param(6, Inject(MatDialogRef)),
863
- __param(7, Optional()), __param(7, Inject(DrawerRef)),
864
- __metadata("design:paramtypes", [NgForm,
865
- FsForm,
866
- ElementRef,
867
- FsMessage,
868
- FsPrompt,
869
- NgZone,
870
- MatDialogRef,
871
- DrawerRef])
872
- ], FsFormDirective);
873
- return FsFormDirective;
874
- }());
875
-
876
- var ERROR_MESSAGES = {
877
- required: 'This field is required',
878
- email: 'This is not a valid email address',
879
- emails: 'Input valid email addresses, comma separated',
880
- phone: 'Invalid phone number',
881
- numeric: 'Value should be numeric',
882
- integer: 'Value should be an integer',
883
- min: 'Value should not be less than $(1)',
884
- max: 'Value should not be greater than $(1)',
885
- minlength: 'Should not be shorter than $(1) characters',
886
- maxlength: 'Should not be longer than $(1) characters',
887
- compare: 'Inputs do not match',
888
- pattern: 'Value should match pattern $(1)',
889
- dateRange: 'Invalid date range',
890
- url: 'This is not a valid url',
891
- urlProtocol: 'Invalid URL. Proper http protocol is required. eg. https://google.com',
892
- greater: 'Value must be greater than $(1)',
893
- lesser: 'Value must be less than $(1)',
894
- };
895
-
896
- var VALIDATE_MESSAGES = new InjectionToken('fs.form.validate-messages');
897
- var VALIDATE_MESSAGE_PROVIDER = {
898
- provide: VALIDATE_MESSAGES,
899
- useFactory: messageProviderFactory,
900
- };
901
- function messageProviderFactory() {
902
- return __assign({}, ERROR_MESSAGES);
903
- }
904
-
905
- var FsControlDirective = /** @class */ (function () {
906
- function FsControlDirective(elementRef, renderer2, injector, _validateMessages, ngControl, formDirective) {
907
- this.elementRef = elementRef;
908
- this.renderer2 = renderer2;
909
- this.injector = injector;
910
- this._validateMessages = _validateMessages;
911
- this.ngControl = ngControl;
912
- this.formDirective = formDirective;
913
- this.appendMessageClass = 'fs-form-message';
914
- this.appendLabelClass = 'fs-form-label';
915
- this.appendErrorClass = 'fs-form-error';
916
- this.appendHintClass = 'fs-form-hint';
917
- this.errors = [];
918
- // protected _validateMessages = { ...ERROR_MESSAGES };
919
- this._destroy$ = new Subject();
920
- if (ngControl) {
921
- this._control = ngControl.control;
922
- }
923
- else {
924
- console.error('The element does not have a valid ngModel', this.elementRef.nativeElement);
925
- }
926
- }
927
- Object.defineProperty(FsControlDirective.prototype, "validateMessages", {
928
- set: function (messages) {
929
- this._validateMessages = __assign(__assign({}, this._validateMessages), messages);
930
- },
931
- enumerable: true,
932
- configurable: true
933
- });
934
- FsControlDirective.prototype.ngOnInit = function () {
935
- this._setupValidators();
936
- };
937
- FsControlDirective.prototype.ngOnDestroy = function () {
938
- this._destroy$.next();
939
- this._destroy$.complete();
940
- };
941
- FsControlDirective.prototype.ngAfterContentInit = function () {
942
- if (this._control) {
943
- /*
944
- Ensure that statusChanges has one subscription per control. Multiple can happen
945
- when multiple fsForm validation directives are applied to the same element
946
- */
947
- if (!this._control.statusChangesSubscribe) {
948
- this._control.statusChanges
949
- .pipe(takeUntil(this._destroy$))
950
- .subscribe(this.render.bind(this));
951
- this._control.statusChangesSubscribe = true;
952
- }
953
- }
954
- };
955
- FsControlDirective.prototype.getMessageSelector = function () {
956
- if (this.messageSelector === false) {
957
- return '';
958
- }
959
- if (this.messageSelector) {
960
- return this.messageSelector;
961
- }
962
- else if (this.formDirective && this.formDirective.messageSelector) {
963
- return this.formDirective.messageSelector;
964
- }
965
- };
966
- FsControlDirective.prototype.getHintWrapperSelector = function () {
967
- if (this.hintSelector === false) {
968
- return '';
969
- }
970
- if (this.hintSelector) {
971
- return this.hintSelector;
972
- }
973
- else if (this.formDirective && this.formDirective.hintSelector) {
974
- return this.formDirective.hintSelector;
975
- }
976
- };
977
- FsControlDirective.prototype.getWrapperSelector = function () {
978
- if (this.wrapperSelector === false) {
979
- return '';
980
- }
981
- if (this.wrapperSelector) {
982
- return this.wrapperSelector;
983
- }
984
- else if (this.formDirective && this.formDirective.wrapperSelector) {
985
- return this.formDirective.wrapperSelector;
986
- }
987
- };
988
- FsControlDirective.prototype.getlabelSelector = function () {
989
- if (this.labelSelector === false) {
990
- return '';
991
- }
992
- if (this.labelSelector) {
993
- return this.labelSelector;
994
- }
995
- else if (this.formDirective && this.formDirective.labelSelector) {
996
- return this.formDirective.labelSelector;
997
- }
998
- };
999
- FsControlDirective.prototype.getWrapperElement = function () {
1000
- var wrapper = this.getWrapper(this.elementRef.nativeElement);
1001
- if (wrapper) {
1002
- return wrapper;
1003
- }
1004
- return this.elementRef.nativeElement;
1005
- };
1006
- /*
1007
- <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.
1008
- <input>
1009
- <div class="fs-form-message"> <-- Message Selector. Look for the element with class .fs-form-message or messageSelector
1010
- <div class="fs-form-message"></div>
1011
- <div class="fs-form-hint"></div> <-- Hint Selector. Look for the element with class .fs-form-hint or hintSelector
1012
- </div>
1013
- </mat-form-field>
1014
- */
1015
- FsControlDirective.prototype.render = function () {
1016
- var _a;
1017
- if (this.ngControl) {
1018
- var renderer = this.renderer2;
1019
- var wrapper = this.getWrapperElement();
1020
- var error = this.ngControl.dirty ? this.getError(this.ngControl) : null;
1021
- if (!this.getMessageSelector()) {
1022
- return;
1023
- }
1024
- var messageWrapper = wrapper.querySelector(this.getMessageSelector());
1025
- if (!messageWrapper) {
1026
- return console.warn('Failed to locate ' + this.getMessageSelector(), this.elementRef.nativeElement);
1027
- }
1028
- if (this.getlabelSelector()) {
1029
- var labelWrapper = wrapper.querySelector(this.getlabelSelector());
1030
- if (labelWrapper) {
1031
- if (this.appendLabelClass) {
1032
- this.renderer2.addClass(labelWrapper, this.appendLabelClass);
1033
- }
1034
- }
1035
- }
1036
- if (this.appendMessageClass) {
1037
- renderer.addClass(messageWrapper, this.appendMessageClass);
1038
- }
1039
- if (this.getHintWrapperSelector()) {
1040
- var hint = messageWrapper.querySelector(this.getHintWrapperSelector());
1041
- if (hint) {
1042
- renderer.setStyle(hint, 'display', error ? 'none' : 'block');
1043
- if (this.appendHintClass) {
1044
- renderer.addClass(hint, this.appendHintClass);
1045
- }
1046
- }
1047
- }
1048
- var errorWrapper = wrapper.querySelector('.fs-form-error-target');
1049
- if (errorWrapper) {
1050
- errorWrapper.remove();
1051
- }
1052
- wrapper.classList.remove('ng-invalid');
1053
- var shouldErrorBeRendered = this.ngControl.invalid
1054
- && (this.ngControl.dirty || ((_a = this.formDirective.ngForm) === null || _a === void 0 ? void 0 : _a.submitted));
1055
- if (!shouldErrorBeRendered || !error) {
1056
- return;
1057
- }
1058
- wrapper.classList.add('ng-invalid');
1059
- errorWrapper = renderer.createElement('div');
1060
- renderer.addClass(errorWrapper, 'fs-form-error-target');
1061
- renderer.addClass(errorWrapper, this.appendErrorClass);
1062
- renderer.addClass(errorWrapper, this.appendErrorClass + '-' + error.name);
1063
- var errorText = renderer.createText(error.message);
1064
- renderer.appendChild(errorWrapper, errorText);
1065
- messageWrapper.appendChild(errorWrapper);
1066
- }
1067
- };
1068
- FsControlDirective.prototype.getWrapper = function (node, count) {
1069
- if (count === void 0) { count = 0; }
1070
- if (!node || count > 10) {
1071
- return null;
1072
- }
1073
- if (node.parentNode && node.parentNode.querySelector(this.getWrapperSelector())) {
1074
- return node;
1075
- }
1076
- return this.getWrapper(node.parentNode, ++count);
1077
- };
1078
- FsControlDirective.prototype.parseErrorMessage = function (message, args) {
1079
- values(args)
1080
- .forEach(function (name) {
1081
- message = message.replace(/\$\(\d\)/, name);
1082
- });
1083
- return message;
1084
- };
1085
- FsControlDirective.prototype.getError = function (controlRef) {
1086
- var name = keys(controlRef.control.errors)[0];
1087
- if (!name) {
1088
- return null;
1089
- }
1090
- var message = controlRef.control.errors[name];
1091
- if (this._validateMessages[name]) {
1092
- message = this.parseErrorMessage(this._validateMessages[name], message);
1093
- }
1094
- return { name: name, message: message };
1095
- };
1096
- FsControlDirective.prototype._setupValidators = function () {
1097
- var control = this._control;
1098
- if (this.validate) {
1099
- var validators = control.validator
1100
- ? [control.validator, this.validate.bind(this)]
1101
- : this.validate.bind(this);
1102
- control.setValidators(validators);
1103
- }
1104
- if (this.validateAsync) {
1105
- var asyncValidators = control.asyncValidator
1106
- ? [control.asyncValidator, this.validateAsync.bind(this)]
1107
- : this.validateAsync.bind(this);
1108
- control.setAsyncValidators(asyncValidators);
1109
- }
1110
- control.updateValueAndValidity();
1111
- };
1112
- FsControlDirective.ctorParameters = function () { return [
1113
- { type: ElementRef },
1114
- { type: Renderer2 },
1115
- { type: Injector },
1116
- { type: undefined, decorators: [{ type: Self }, { type: Inject, args: [VALIDATE_MESSAGES,] }] },
1117
- { type: NgControl, decorators: [{ type: Optional }] },
1118
- { type: FsFormDirective, decorators: [{ type: Optional }, { type: Inject, args: [FsFormDirective,] }] }
1119
- ]; };
1120
- __decorate([
1121
- Input(),
1122
- __metadata("design:type", Object)
1123
- ], FsControlDirective.prototype, "wrapperSelector", void 0);
1124
- __decorate([
1125
- Input(),
1126
- __metadata("design:type", Object)
1127
- ], FsControlDirective.prototype, "messageSelector", void 0);
1128
- __decorate([
1129
- Input(),
1130
- __metadata("design:type", Object)
1131
- ], FsControlDirective.prototype, "hintSelector", void 0);
1132
- __decorate([
1133
- Input(),
1134
- __metadata("design:type", Object)
1135
- ], FsControlDirective.prototype, "labelSelector", void 0);
1136
- __decorate([
1137
- Input(),
1138
- __metadata("design:type", Object)
1139
- ], FsControlDirective.prototype, "appendMessageClass", void 0);
1140
- __decorate([
1141
- Input(),
1142
- __metadata("design:type", Object)
1143
- ], FsControlDirective.prototype, "appendLabelClass", void 0);
1144
- __decorate([
1145
- Input(),
1146
- __metadata("design:type", Object)
1147
- ], FsControlDirective.prototype, "appendErrorClass", void 0);
1148
- __decorate([
1149
- Input(),
1150
- __metadata("design:type", Object)
1151
- ], FsControlDirective.prototype, "appendHintClass", void 0);
1152
- __decorate([
1153
- Input(),
1154
- __metadata("design:type", Object),
1155
- __metadata("design:paramtypes", [Object])
1156
- ], FsControlDirective.prototype, "validateMessages", null);
1157
- FsControlDirective = __decorate([
1158
- Directive({
1159
- selector: '[fsFormControl]',
1160
- providers: [
1161
- VALIDATE_MESSAGE_PROVIDER
1162
- ],
1163
- }),
1164
- __param(3, Self()), __param(3, Inject(VALIDATE_MESSAGES)),
1165
- __param(4, Optional()),
1166
- __param(5, Optional()), __param(5, Inject(FsFormDirective)),
1167
- __metadata("design:paramtypes", [ElementRef,
1168
- Renderer2,
1169
- Injector, Object, NgControl,
1170
- FsFormDirective])
1171
- ], FsControlDirective);
1172
- return FsControlDirective;
1173
- }());
1174
-
1175
- function isEnabled(value) {
1176
- return value !== 'false' && (value || value === '');
1177
- }
1178
-
1179
- var FsFormRequiredDirective = /** @class */ (function (_super) {
1180
- __extends(FsFormRequiredDirective, _super);
1181
- function FsFormRequiredDirective() {
1182
- var _this = _super !== null && _super.apply(this, arguments) || this;
1183
- _this.required = false;
1184
- return _this;
1185
- }
1186
- Object.defineProperty(FsFormRequiredDirective.prototype, "setFsFormRequired", {
1187
- set: function (value) {
1188
- this.required = isEnabled(value);
1189
- },
1190
- enumerable: true,
1191
- configurable: true
1192
- });
1193
- Object.defineProperty(FsFormRequiredDirective.prototype, "setRequired", {
1194
- set: function (value) {
1195
- this.required = isEnabled(value);
1196
- },
1197
- enumerable: true,
1198
- configurable: true
1199
- });
1200
- Object.defineProperty(FsFormRequiredDirective.prototype, "validationMessage", {
1201
- set: function (value) {
1202
- this._validateMessages.required = value;
1203
- },
1204
- enumerable: true,
1205
- configurable: true
1206
- });
1207
- FsFormRequiredDirective.prototype.ngOnChanges = function () {
1208
- this._control.updateValueAndValidity();
1209
- };
1210
- FsFormRequiredDirective.prototype.validate = function (control) {
1211
- if (this.required) {
1212
- return Validators.required(this._control);
1213
- }
1214
- else {
1215
- return null;
1216
- }
1217
- };
1218
- FsFormRequiredDirective.prototype.render = function () {
1219
- var wrapper = this.getWrapperElement();
1220
- if (wrapper && this.getlabelSelector()) {
1221
- var labelWrapper = wrapper.querySelector(this.getlabelSelector());
1222
- // Adding class fs-form-label-requried adds the * to the label
1223
- if (labelWrapper) {
1224
- if (this.required) {
1225
- this.renderer2.addClass(labelWrapper, 'fs-form-label-required');
1226
- }
1227
- else {
1228
- this.renderer2.removeClass(labelWrapper, 'fs-form-label-required');
1229
- }
1230
- }
1231
- }
1232
- _super.prototype.render.call(this);
1233
- };
1234
- __decorate([
1235
- Input('fsFormRequired'),
1236
- __metadata("design:type", Object),
1237
- __metadata("design:paramtypes", [Object])
1238
- ], FsFormRequiredDirective.prototype, "setFsFormRequired", null);
1239
- __decorate([
1240
- Input('required'),
1241
- __metadata("design:type", Object),
1242
- __metadata("design:paramtypes", [Object])
1243
- ], FsFormRequiredDirective.prototype, "setRequired", null);
1244
- __decorate([
1245
- Input('fsFormRequiredMessage'),
1246
- __metadata("design:type", String),
1247
- __metadata("design:paramtypes", [String])
1248
- ], FsFormRequiredDirective.prototype, "validationMessage", null);
1249
- FsFormRequiredDirective = __decorate([
1250
- Directive({
1251
- selector: '[fsFormRequired],[ngModel][required]',
1252
- providers: [
1253
- VALIDATE_MESSAGE_PROVIDER
1254
- ],
1255
- })
1256
- ], FsFormRequiredDirective);
1257
- return FsFormRequiredDirective;
1258
- }(FsControlDirective));
1259
-
1260
- var FsValidators = /** @class */ (function () {
1261
- function FsValidators() {
1262
- }
1263
- FsValidators.email = function (control) {
1264
- if (!control.value || email(control.value)) {
1265
- return null;
1266
- }
1267
- return { email: true };
1268
- };
1269
- FsValidators.emails = function (control) {
1270
- var model = control.value || '';
1271
- var hasInvalidEmails = model
1272
- .split(',')
1273
- .some(function (part) { return !email(part); });
1274
- return hasInvalidEmails ? { email: true } : null;
1275
- };
1276
- FsValidators.numeric = function (control) {
1277
- if (isEmpty(control.value) || isNumeric(control.value)) {
1278
- return null;
1279
- }
1280
- else {
1281
- return { numeric: true };
1282
- }
1283
- };
1284
- FsValidators.integer = function (control) {
1285
- if (!control.value || String(control.value) === '' || (control.value % 1 === 0)) {
1286
- return null;
1287
- }
1288
- else {
1289
- return { integer: true };
1290
- }
1291
- };
1292
- FsValidators.phone = function (control) {
1293
- if (!control.value || phone(control.value)) {
1294
- return null;
1295
- }
1296
- return { phone: true };
1297
- };
1298
- FsValidators.url = function (control, protocolRequired) {
1299
- if (protocolRequired === void 0) { protocolRequired = false; }
1300
- if (!control.value) {
1301
- return null;
1302
- }
1303
- if (!url(control.value)) {
1304
- return { url: true };
1305
- }
1306
- if (protocolRequired) {
1307
- var pattern = new RegExp(/^http(s)?:\/\//gm);
1308
- if (!String(control.value).match(pattern)) {
1309
- return { urlProtocol: true };
1310
- }
1311
- }
1312
- return null;
1313
- };
1314
- FsValidators.dateRange = function (control) {
1315
- if (!control.value) {
1316
- return null;
1317
- }
1318
- if (isObject(control.value)) {
1319
- var start = control.value.start;
1320
- var end = control.value.end;
1321
- if ((!start && !end) || (isValid(start) && isValid(end))) {
1322
- return null;
1323
- }
1324
- }
1325
- return { dateRange: true };
1326
- };
1327
- FsValidators.func = function (control, formFunction, data) {
1328
- var result;
1329
- var stream$;
1330
- try {
1331
- result = formFunction(control, data);
1332
- }
1333
- catch (err) {
1334
- err = err instanceof Error ? err.message : err;
1335
- stream$ = throwError(err);
1336
- }
1337
- if (!stream$) {
1338
- if (result instanceof Promise) {
1339
- stream$ = from(result);
1340
- }
1341
- else if (isObservable(result)) {
1342
- stream$ = result;
1343
- }
1344
- else {
1345
- stream$ = of(null);
1346
- }
1347
- }
1348
- return stream$
1349
- .pipe(map(function () { return null; }), catchError(function (err) {
1350
- return of({ validationError: err });
1351
- }), take(1));
1352
- };
1353
- return FsValidators;
1354
- }());
1355
-
1356
- var FsFormMinDirective = /** @class */ (function (_super) {
1357
- __extends(FsFormMinDirective, _super);
1358
- function FsFormMinDirective() {
1359
- return _super !== null && _super.apply(this, arguments) || this;
1360
- }
1361
- Object.defineProperty(FsFormMinDirective.prototype, "validationMessage", {
1362
- set: function (value) {
1363
- this._validateMessages.min = value;
1364
- },
1365
- enumerable: true,
1366
- configurable: true
1367
- });
1368
- FsFormMinDirective.prototype.ngOnChanges = function () {
1369
- this._control.updateValueAndValidity();
1370
- };
1371
- FsFormMinDirective.prototype.validate = function (control) {
1372
- return FsValidators.numeric(this._control) || Validators.min(parseFloat(this.fsFormMin))(this._control);
1373
- };
1374
- __decorate([
1375
- Input(),
1376
- __metadata("design:type", Object)
1377
- ], FsFormMinDirective.prototype, "fsFormMin", void 0);
1378
- __decorate([
1379
- Input('fsFormMinMessage'),
1380
- __metadata("design:type", String),
1381
- __metadata("design:paramtypes", [String])
1382
- ], FsFormMinDirective.prototype, "validationMessage", null);
1383
- FsFormMinDirective = __decorate([
1384
- Directive({
1385
- selector: '[fsFormMin]',
1386
- providers: [
1387
- VALIDATE_MESSAGE_PROVIDER
1388
- ],
1389
- })
1390
- ], FsFormMinDirective);
1391
- return FsFormMinDirective;
1392
- }(FsControlDirective));
1393
-
1394
- var FsFormMaxDirective = /** @class */ (function (_super) {
1395
- __extends(FsFormMaxDirective, _super);
1396
- function FsFormMaxDirective() {
1397
- return _super !== null && _super.apply(this, arguments) || this;
1398
- }
1399
- Object.defineProperty(FsFormMaxDirective.prototype, "validationMessage", {
1400
- set: function (value) {
1401
- this._validateMessages.max = value;
1402
- },
1403
- enumerable: true,
1404
- configurable: true
1405
- });
1406
- FsFormMaxDirective.prototype.ngOnChanges = function () {
1407
- this._control.updateValueAndValidity();
1408
- };
1409
- FsFormMaxDirective.prototype.validate = function (control) {
1410
- return FsValidators.numeric(this._control) || Validators.max(this.fsFormMax)(this._control);
1411
- };
1412
- __decorate([
1413
- Input(),
1414
- __metadata("design:type", Number)
1415
- ], FsFormMaxDirective.prototype, "fsFormMax", void 0);
1416
- __decorate([
1417
- Input('fsFormMaxMessage'),
1418
- __metadata("design:type", String),
1419
- __metadata("design:paramtypes", [String])
1420
- ], FsFormMaxDirective.prototype, "validationMessage", null);
1421
- FsFormMaxDirective = __decorate([
1422
- Directive({
1423
- selector: '[fsFormMax]',
1424
- providers: [
1425
- VALIDATE_MESSAGE_PROVIDER
1426
- ],
1427
- })
1428
- ], FsFormMaxDirective);
1429
- return FsFormMaxDirective;
1430
- }(FsControlDirective));
1431
-
1432
- var FsFormMinLengthDirective = /** @class */ (function (_super) {
1433
- __extends(FsFormMinLengthDirective, _super);
1434
- function FsFormMinLengthDirective() {
1435
- return _super !== null && _super.apply(this, arguments) || this;
1436
- }
1437
- Object.defineProperty(FsFormMinLengthDirective.prototype, "validationMessage", {
1438
- set: function (value) {
1439
- this._validateMessages.minlength = value;
1440
- },
1441
- enumerable: true,
1442
- configurable: true
1443
- });
1444
- FsFormMinLengthDirective.prototype.ngOnChanges = function () {
1445
- this._control.updateValueAndValidity();
1446
- };
1447
- FsFormMinLengthDirective.prototype.validate = function (control) {
1448
- return Validators.minLength(this.fsFormMinLength)(this._control);
1449
- };
1450
- __decorate([
1451
- Input(),
1452
- __metadata("design:type", Number)
1453
- ], FsFormMinLengthDirective.prototype, "fsFormMinLength", void 0);
1454
- __decorate([
1455
- Input('fsFormMinLengthMessage'),
1456
- __metadata("design:type", String),
1457
- __metadata("design:paramtypes", [String])
1458
- ], FsFormMinLengthDirective.prototype, "validationMessage", null);
1459
- FsFormMinLengthDirective = __decorate([
1460
- Directive({
1461
- selector: '[fsFormMinLength]',
1462
- providers: [
1463
- VALIDATE_MESSAGE_PROVIDER
1464
- ],
1465
- })
1466
- ], FsFormMinLengthDirective);
1467
- return FsFormMinLengthDirective;
1468
- }(FsControlDirective));
1469
-
1470
- var FsFormMaxLengthDirective = /** @class */ (function (_super) {
1471
- __extends(FsFormMaxLengthDirective, _super);
1472
- function FsFormMaxLengthDirective() {
1473
- return _super !== null && _super.apply(this, arguments) || this;
1474
- }
1475
- Object.defineProperty(FsFormMaxLengthDirective.prototype, "validationMessage", {
1476
- set: function (value) {
1477
- this._validateMessages.maxlength = value;
1478
- },
1479
- enumerable: true,
1480
- configurable: true
1481
- });
1482
- FsFormMaxLengthDirective.prototype.ngOnChanges = function () {
1483
- this._control.updateValueAndValidity();
1484
- };
1485
- FsFormMaxLengthDirective.prototype.validate = function (control) {
1486
- return Validators.maxLength(this.fsFormMaxLength)(this._control);
1487
- };
1488
- __decorate([
1489
- Input(),
1490
- __metadata("design:type", Number)
1491
- ], FsFormMaxLengthDirective.prototype, "fsFormMaxLength", void 0);
1492
- __decorate([
1493
- Input('fsFormMaxLengthMessage'),
1494
- __metadata("design:type", String),
1495
- __metadata("design:paramtypes", [String])
1496
- ], FsFormMaxLengthDirective.prototype, "validationMessage", null);
1497
- FsFormMaxLengthDirective = __decorate([
1498
- Directive({
1499
- selector: '[fsFormMaxLength]',
1500
- providers: [
1501
- VALIDATE_MESSAGE_PROVIDER
1502
- ],
1503
- })
1504
- ], FsFormMaxLengthDirective);
1505
- return FsFormMaxLengthDirective;
1506
- }(FsControlDirective));
1507
-
1508
- var FsFormEmailDirective = /** @class */ (function (_super) {
1509
- __extends(FsFormEmailDirective, _super);
1510
- function FsFormEmailDirective() {
1511
- return _super !== null && _super.apply(this, arguments) || this;
1512
- }
1513
- Object.defineProperty(FsFormEmailDirective.prototype, "validationMessage", {
1514
- set: function (value) {
1515
- this._validateMessages.email = value;
1516
- },
1517
- enumerable: true,
1518
- configurable: true
1519
- });
1520
- FsFormEmailDirective.prototype.ngOnChanges = function () {
1521
- this._control.updateValueAndValidity();
1522
- };
1523
- FsFormEmailDirective.prototype.validate = function (control) {
1524
- if (isEnabled(this.fsFormEmail)) {
1525
- return FsValidators.email(this._control);
1526
- }
1527
- else {
1528
- return null;
1529
- }
1530
- };
1531
- __decorate([
1532
- Input(),
1533
- __metadata("design:type", Object)
1534
- ], FsFormEmailDirective.prototype, "fsFormEmail", void 0);
1535
- __decorate([
1536
- Input('fsFormEmailMessage'),
1537
- __metadata("design:type", String),
1538
- __metadata("design:paramtypes", [String])
1539
- ], FsFormEmailDirective.prototype, "validationMessage", null);
1540
- FsFormEmailDirective = __decorate([
1541
- Directive({
1542
- selector: '[fsFormEmail]',
1543
- providers: [
1544
- VALIDATE_MESSAGE_PROVIDER
1545
- ],
1546
- })
1547
- ], FsFormEmailDirective);
1548
- return FsFormEmailDirective;
1549
- }(FsControlDirective));
1550
-
1551
- var FsFormEmailsDirective = /** @class */ (function (_super) {
1552
- __extends(FsFormEmailsDirective, _super);
1553
- function FsFormEmailsDirective() {
1554
- return _super !== null && _super.apply(this, arguments) || this;
1555
- }
1556
- Object.defineProperty(FsFormEmailsDirective.prototype, "validationMessage", {
1557
- set: function (value) {
1558
- this._validateMessages.emails = value;
1559
- },
1560
- enumerable: true,
1561
- configurable: true
1562
- });
1563
- FsFormEmailsDirective.prototype.ngOnChanges = function () {
1564
- this._control.updateValueAndValidity();
1565
- };
1566
- FsFormEmailsDirective.prototype.validate = function (control) {
1567
- if (isEnabled(this.fsFormEmails)) {
1568
- return FsValidators.emails(this._control);
1569
- }
1570
- else {
1571
- return null;
1572
- }
1573
- };
1574
- __decorate([
1575
- Input(),
1576
- __metadata("design:type", Object)
1577
- ], FsFormEmailsDirective.prototype, "fsFormEmails", void 0);
1578
- __decorate([
1579
- Input('fsFormEmailsMessage'),
1580
- __metadata("design:type", String),
1581
- __metadata("design:paramtypes", [String])
1582
- ], FsFormEmailsDirective.prototype, "validationMessage", null);
1583
- FsFormEmailsDirective = __decorate([
1584
- Directive({
1585
- selector: '[fsFormEmails]',
1586
- providers: [
1587
- VALIDATE_MESSAGE_PROVIDER
1588
- ],
1589
- })
1590
- ], FsFormEmailsDirective);
1591
- return FsFormEmailsDirective;
1592
- }(FsControlDirective));
1593
-
1594
- var FsFormPhoneDirective = /** @class */ (function (_super) {
1595
- __extends(FsFormPhoneDirective, _super);
1596
- function FsFormPhoneDirective() {
1597
- return _super !== null && _super.apply(this, arguments) || this;
1598
- }
1599
- Object.defineProperty(FsFormPhoneDirective.prototype, "validationMessage", {
1600
- set: function (value) {
1601
- this._validateMessages.phone = value;
1602
- },
1603
- enumerable: true,
1604
- configurable: true
1605
- });
1606
- FsFormPhoneDirective.prototype.ngOnChanges = function () {
1607
- this._control.updateValueAndValidity();
1608
- };
1609
- FsFormPhoneDirective.prototype.validate = function (control) {
1610
- if (isEnabled(this.fsFormPhone)) {
1611
- return FsValidators.phone(this._control);
1612
- }
1613
- else {
1614
- return null;
1615
- }
1616
- };
1617
- __decorate([
1618
- Input(),
1619
- __metadata("design:type", Object)
1620
- ], FsFormPhoneDirective.prototype, "fsFormPhone", void 0);
1621
- __decorate([
1622
- Input('fsFormPhoneMessage'),
1623
- __metadata("design:type", String),
1624
- __metadata("design:paramtypes", [String])
1625
- ], FsFormPhoneDirective.prototype, "validationMessage", null);
1626
- FsFormPhoneDirective = __decorate([
1627
- Directive({
1628
- selector: '[fsFormPhone]',
1629
- providers: [
1630
- VALIDATE_MESSAGE_PROVIDER
1631
- ],
1632
- })
1633
- ], FsFormPhoneDirective);
1634
- return FsFormPhoneDirective;
1635
- }(FsControlDirective));
1636
-
1637
- var FsFormCompareDirective = /** @class */ (function (_super) {
1638
- __extends(FsFormCompareDirective, _super);
1639
- function FsFormCompareDirective() {
1640
- return _super !== null && _super.apply(this, arguments) || this;
1641
- }
1642
- Object.defineProperty(FsFormCompareDirective.prototype, "validationMessage", {
1643
- set: function (value) {
1644
- this._validateMessages.compare = value;
1645
- },
1646
- enumerable: true,
1647
- configurable: true
1648
- });
1649
- FsFormCompareDirective.prototype.ngOnChanges = function () {
1650
- this._control.updateValueAndValidity();
1651
- };
1652
- FsFormCompareDirective.prototype.validate = function (control) {
1653
- if (this.fsFormCompare.value === this.elementRef.nativeElement.value) {
1654
- return null;
1655
- }
1656
- else {
1657
- return { compare: true };
1658
- }
1659
- };
1660
- FsFormCompareDirective.prototype.ngAfterViewInit = function () {
1661
- var _this = this;
1662
- this.fsFormCompare.addEventListener('keyup', function () {
1663
- _this._control.updateValueAndValidity();
1664
- }, false);
1665
- };
1666
- FsFormCompareDirective.prototype.ngOnDestroy = function () {
1667
- var _this = this;
1668
- this.fsFormCompare.removeEventListener('keyup', function () {
1669
- _this._control.updateValueAndValidity();
1670
- }, false);
1671
- };
1672
- __decorate([
1673
- Input(),
1674
- __metadata("design:type", Object)
1675
- ], FsFormCompareDirective.prototype, "fsFormCompare", void 0);
1676
- __decorate([
1677
- Input('fsFormCompareMessage'),
1678
- __metadata("design:type", String),
1679
- __metadata("design:paramtypes", [String])
1680
- ], FsFormCompareDirective.prototype, "validationMessage", null);
1681
- FsFormCompareDirective = __decorate([
1682
- Directive({
1683
- selector: '[fsFormCompare]',
1684
- providers: [
1685
- VALIDATE_MESSAGE_PROVIDER,
1686
- ],
1687
- })
1688
- ], FsFormCompareDirective);
1689
- return FsFormCompareDirective;
1690
- }(FsControlDirective));
1691
-
1692
- var FsFormIntegerDirective = /** @class */ (function (_super) {
1693
- __extends(FsFormIntegerDirective, _super);
1694
- function FsFormIntegerDirective() {
1695
- return _super !== null && _super.apply(this, arguments) || this;
1696
- }
1697
- Object.defineProperty(FsFormIntegerDirective.prototype, "validationMessage", {
1698
- set: function (value) {
1699
- this._validateMessages.integer = value;
1700
- },
1701
- enumerable: true,
1702
- configurable: true
1703
- });
1704
- FsFormIntegerDirective.prototype.ngOnChanges = function () {
1705
- this._control.updateValueAndValidity();
1706
- };
1707
- FsFormIntegerDirective.prototype.validate = function (control) {
1708
- if (isEnabled(this.fsFormInteger)) {
1709
- return FsValidators.integer(this._control);
1710
- }
1711
- else {
1712
- return null;
1713
- }
1714
- };
1715
- __decorate([
1716
- Input(),
1717
- __metadata("design:type", Object)
1718
- ], FsFormIntegerDirective.prototype, "fsFormInteger", void 0);
1719
- __decorate([
1720
- Input('fsFormIntegerMessage'),
1721
- __metadata("design:type", String),
1722
- __metadata("design:paramtypes", [String])
1723
- ], FsFormIntegerDirective.prototype, "validationMessage", null);
1724
- FsFormIntegerDirective = __decorate([
1725
- Directive({
1726
- selector: '[fsFormInteger]',
1727
- providers: [
1728
- VALIDATE_MESSAGE_PROVIDER
1729
- ],
1730
- })
1731
- ], FsFormIntegerDirective);
1732
- return FsFormIntegerDirective;
1733
- }(FsControlDirective));
1734
-
1735
- var FsFormNumericDirective = /** @class */ (function (_super) {
1736
- __extends(FsFormNumericDirective, _super);
1737
- function FsFormNumericDirective() {
1738
- return _super !== null && _super.apply(this, arguments) || this;
1739
- }
1740
- Object.defineProperty(FsFormNumericDirective.prototype, "validationMessage", {
1741
- set: function (value) {
1742
- this._validateMessages.numeric = value;
1743
- },
1744
- enumerable: true,
1745
- configurable: true
1746
- });
1747
- FsFormNumericDirective.prototype.ngOnChanges = function () {
1748
- this._control.updateValueAndValidity();
1749
- };
1750
- FsFormNumericDirective.prototype.validate = function (control) {
1751
- if (isEnabled(this.fsFormNumeric)) {
1752
- return FsValidators.numeric(this._control);
1753
- }
1754
- else {
1755
- return null;
1756
- }
1757
- };
1758
- __decorate([
1759
- Input(),
1760
- __metadata("design:type", Object)
1761
- ], FsFormNumericDirective.prototype, "fsFormNumeric", void 0);
1762
- __decorate([
1763
- Input('fsFormNumericMessage'),
1764
- __metadata("design:type", String),
1765
- __metadata("design:paramtypes", [String])
1766
- ], FsFormNumericDirective.prototype, "validationMessage", null);
1767
- FsFormNumericDirective = __decorate([
1768
- Directive({
1769
- selector: '[fsFormNumeric]',
1770
- providers: [
1771
- VALIDATE_MESSAGE_PROVIDER
1772
- ],
1773
- })
1774
- ], FsFormNumericDirective);
1775
- return FsFormNumericDirective;
1776
- }(FsControlDirective));
1777
-
1778
- var FsFormPatternDirective = /** @class */ (function (_super) {
1779
- __extends(FsFormPatternDirective, _super);
1780
- function FsFormPatternDirective() {
1781
- return _super !== null && _super.apply(this, arguments) || this;
1782
- }
1783
- Object.defineProperty(FsFormPatternDirective.prototype, "validationMessage", {
1784
- set: function (value) {
1785
- this._validateMessages.pattern = value;
1786
- },
1787
- enumerable: true,
1788
- configurable: true
1789
- });
1790
- FsFormPatternDirective.prototype.ngOnChanges = function () {
1791
- this._control.updateValueAndValidity();
1792
- };
1793
- FsFormPatternDirective.prototype.validate = function (control) {
1794
- return Validators.pattern(this.fsFormPattern)(this._control);
1795
- };
1796
- __decorate([
1797
- Input(),
1798
- __metadata("design:type", RegExp)
1799
- ], FsFormPatternDirective.prototype, "fsFormPattern", void 0);
1800
- __decorate([
1801
- Input('fsFormPatternMessage'),
1802
- __metadata("design:type", String),
1803
- __metadata("design:paramtypes", [String])
1804
- ], FsFormPatternDirective.prototype, "validationMessage", null);
1805
- FsFormPatternDirective = __decorate([
1806
- Directive({
1807
- selector: '[fsFormPattern]',
1808
- providers: [
1809
- VALIDATE_MESSAGE_PROVIDER
1810
- ],
1811
- })
1812
- ], FsFormPatternDirective);
1813
- return FsFormPatternDirective;
1814
- }(FsControlDirective));
1815
-
1816
- var FsFormFunctionDirective = /** @class */ (function (_super) {
1817
- __extends(FsFormFunctionDirective, _super);
1818
- function FsFormFunctionDirective() {
1819
- return _super !== null && _super.apply(this, arguments) || this;
1820
- }
1821
- FsFormFunctionDirective.prototype.ngOnChanges = function () {
1822
- this._control.updateValueAndValidity();
1823
- };
1824
- FsFormFunctionDirective.prototype.validateAsync = function (control) {
1825
- return FsValidators.func(this._control, this.fsFormFunction, this.fsFormFunctionData);
1826
- };
1827
- __decorate([
1828
- Input(),
1829
- __metadata("design:type", Object)
1830
- ], FsFormFunctionDirective.prototype, "fsFormFunction", void 0);
1831
- __decorate([
1832
- Input(),
1833
- __metadata("design:type", Object)
1834
- ], FsFormFunctionDirective.prototype, "fsFormFunctionData", void 0);
1835
- FsFormFunctionDirective = __decorate([
1836
- Directive({
1837
- selector: '[fsFormFunction]',
1838
- providers: [
1839
- VALIDATE_MESSAGE_PROVIDER
1840
- ],
1841
- })
1842
- ], FsFormFunctionDirective);
1843
- return FsFormFunctionDirective;
1844
- }(FsControlDirective));
1845
-
1846
- var FsFormGreaterDirective = /** @class */ (function (_super) {
1847
- __extends(FsFormGreaterDirective, _super);
1848
- function FsFormGreaterDirective() {
1849
- return _super !== null && _super.apply(this, arguments) || this;
1850
- }
1851
- Object.defineProperty(FsFormGreaterDirective.prototype, "validationMessage", {
1852
- set: function (value) {
1853
- this._validateMessages.greater = value;
1854
- },
1855
- enumerable: true,
1856
- configurable: true
1857
- });
1858
- FsFormGreaterDirective.prototype.ngOnChanges = function () {
1859
- this._control.updateValueAndValidity();
1860
- };
1861
- FsFormGreaterDirective.prototype.validate = function (control) {
1862
- var greater = parseFloat(this.fsFormGreater);
1863
- var value = parseFloat(this._control.value);
1864
- if (!isNaN(greater) && !isNaN(value) && value <= greater) {
1865
- return { greater: { greater: greater, actual: value } };
1866
- }
1867
- return FsValidators.numeric(this._control);
1868
- };
1869
- __decorate([
1870
- Input(),
1871
- __metadata("design:type", Object)
1872
- ], FsFormGreaterDirective.prototype, "fsFormGreater", void 0);
1873
- __decorate([
1874
- Input('fsFormGreaterMessage'),
1875
- __metadata("design:type", String),
1876
- __metadata("design:paramtypes", [String])
1877
- ], FsFormGreaterDirective.prototype, "validationMessage", null);
1878
- FsFormGreaterDirective = __decorate([
1879
- Directive({
1880
- selector: '[fsFormGreater]',
1881
- providers: [
1882
- VALIDATE_MESSAGE_PROVIDER
1883
- ],
1884
- })
1885
- ], FsFormGreaterDirective);
1886
- return FsFormGreaterDirective;
1887
- }(FsControlDirective));
1888
-
1889
- var FsFormDateRangeDirective = /** @class */ (function (_super) {
1890
- __extends(FsFormDateRangeDirective, _super);
1891
- function FsFormDateRangeDirective() {
1892
- return _super !== null && _super.apply(this, arguments) || this;
1893
- }
1894
- Object.defineProperty(FsFormDateRangeDirective.prototype, "validationMessage", {
1895
- set: function (value) {
1896
- this._validateMessages.dateRange = value;
1897
- },
1898
- enumerable: true,
1899
- configurable: true
1900
- });
1901
- FsFormDateRangeDirective.prototype.ngOnChanges = function () {
1902
- this._control.updateValueAndValidity();
1903
- };
1904
- FsFormDateRangeDirective.prototype.validate = function (control) {
1905
- if (isEnabled(this.fsFormDateRange)) {
1906
- return FsValidators.dateRange(this._control);
1907
- }
1908
- else {
1909
- return null;
1910
- }
1911
- };
1912
- __decorate([
1913
- Input(),
1914
- __metadata("design:type", Object)
1915
- ], FsFormDateRangeDirective.prototype, "fsFormDateRange", void 0);
1916
- __decorate([
1917
- Input('fsFormDateRangeMessage'),
1918
- __metadata("design:type", String),
1919
- __metadata("design:paramtypes", [String])
1920
- ], FsFormDateRangeDirective.prototype, "validationMessage", null);
1921
- FsFormDateRangeDirective = __decorate([
1922
- Directive({
1923
- selector: '[fsFormDateRange]',
1924
- providers: [
1925
- VALIDATE_MESSAGE_PROVIDER
1926
- ],
1927
- })
1928
- ], FsFormDateRangeDirective);
1929
- return FsFormDateRangeDirective;
1930
- }(FsControlDirective));
1931
-
1932
- var FsFormLesserDirective = /** @class */ (function (_super) {
1933
- __extends(FsFormLesserDirective, _super);
1934
- function FsFormLesserDirective() {
1935
- return _super !== null && _super.apply(this, arguments) || this;
1936
- }
1937
- Object.defineProperty(FsFormLesserDirective.prototype, "validationMessage", {
1938
- set: function (value) {
1939
- this._validateMessages.lesser = value;
1940
- },
1941
- enumerable: true,
1942
- configurable: true
1943
- });
1944
- FsFormLesserDirective.prototype.ngOnChanges = function () {
1945
- this._control.updateValueAndValidity();
1946
- };
1947
- FsFormLesserDirective.prototype.validate = function (control) {
1948
- var lesser = parseFloat(this.fsFormLesser);
1949
- var value = parseFloat(this._control.value);
1950
- if (!isNaN(lesser) && !isNaN(value) && value >= lesser) {
1951
- return { lesser: { lesser: lesser, actual: value } };
1952
- }
1953
- return FsValidators.numeric(this._control);
1954
- };
1955
- __decorate([
1956
- Input(),
1957
- __metadata("design:type", Object)
1958
- ], FsFormLesserDirective.prototype, "fsFormLesser", void 0);
1959
- __decorate([
1960
- Input('fsFormLesserMessage'),
1961
- __metadata("design:type", String),
1962
- __metadata("design:paramtypes", [String])
1963
- ], FsFormLesserDirective.prototype, "validationMessage", null);
1964
- FsFormLesserDirective = __decorate([
1965
- Directive({
1966
- selector: '[fsFormLesser]',
1967
- providers: [
1968
- VALIDATE_MESSAGE_PROVIDER
1969
- ],
1970
- })
1971
- ], FsFormLesserDirective);
1972
- return FsFormLesserDirective;
1973
- }(FsControlDirective));
1974
-
1975
- var FsFormUrlDirective = /** @class */ (function (_super) {
1976
- __extends(FsFormUrlDirective, _super);
1977
- function FsFormUrlDirective() {
1978
- var _this = _super !== null && _super.apply(this, arguments) || this;
1979
- _this.fsFormUrlProtocol = false;
1980
- return _this;
1981
- }
1982
- Object.defineProperty(FsFormUrlDirective.prototype, "validationMessage", {
1983
- set: function (value) {
1984
- this._validateMessages.url = value;
1985
- },
1986
- enumerable: true,
1987
- configurable: true
1988
- });
1989
- FsFormUrlDirective.prototype.ngOnChanges = function () {
1990
- this._control.updateValueAndValidity();
1991
- };
1992
- FsFormUrlDirective.prototype.validate = function (control) {
1993
- if (isEnabled(this.fsFormUrl)) {
1994
- return FsValidators.url(this._control, this.fsFormUrlProtocol);
1995
- }
1996
- else {
1997
- return null;
1998
- }
1999
- };
2000
- __decorate([
2001
- Input(),
2002
- __metadata("design:type", Object)
2003
- ], FsFormUrlDirective.prototype, "fsFormUrl", void 0);
2004
- __decorate([
2005
- Input(),
2006
- __metadata("design:type", Object)
2007
- ], FsFormUrlDirective.prototype, "fsFormUrlProtocol", void 0);
2008
- __decorate([
2009
- Input('fsFormUrlMessage'),
2010
- __metadata("design:type", String),
2011
- __metadata("design:paramtypes", [String])
2012
- ], FsFormUrlDirective.prototype, "validationMessage", null);
2013
- FsFormUrlDirective = __decorate([
2014
- Directive({
2015
- selector: '[fsFormUrl]',
2016
- providers: [
2017
- VALIDATE_MESSAGE_PROVIDER
2018
- ],
2019
- })
2020
- ], FsFormUrlDirective);
2021
- return FsFormUrlDirective;
2022
- }(FsControlDirective));
2023
-
2024
- var FsSubmitButtonDirective = /** @class */ (function () {
2025
- function FsSubmitButtonDirective(_matButton, _form, _elementRef, _cdRef) {
2026
- this._matButton = _matButton;
2027
- this._form = _form;
2028
- this._elementRef = _elementRef;
2029
- this._cdRef = _cdRef;
2030
- this.dirtySubmit = true;
2031
- this.transitionStyle = null;
2032
- this.active = false;
2033
- this._destroy$ = new Subject();
2034
- }
2035
- FsSubmitButtonDirective.prototype.ngOnInit = function () {
2036
- var _this = this;
2037
- if (this._form) {
2038
- this._form.addSubmitButton(this);
2039
- fromEvent(this.element, 'click')
2040
- .pipe(takeUntil(this._destroy$))
2041
- .subscribe(function () {
2042
- _this.active = true;
2043
- });
2044
- if (this.dirtySubmit) {
2045
- if (this._form.dirtySubmitButton) {
2046
- if (!this._form.ngForm.dirty) {
2047
- this.disable();
2048
- }
2049
- }
2050
- }
2051
- this.transitionStyle = 'none';
2052
- setTimeout(function () {
2053
- _this.transitionStyle = null;
2054
- }, 500);
2055
- }
2056
- };
2057
- FsSubmitButtonDirective.prototype.disable = function () {
2058
- if (this._matButton) {
2059
- this._matButton.disabled = true;
2060
- this._cdRef.markForCheck();
2061
- }
2062
- };
2063
- FsSubmitButtonDirective.prototype.enable = function () {
2064
- if (this._matButton) {
2065
- this._matButton.disabled = false;
2066
- this._matButton.disableRipple = true;
2067
- this._cdRef.markForCheck();
2068
- }
2069
- };
2070
- FsSubmitButtonDirective.prototype.process = function () {
2071
- this.setClass('process');
2072
- this._matButton.disableRipple = true;
2073
- };
2074
- FsSubmitButtonDirective.prototype.success = function () {
2075
- this.setClass('success');
2076
- this._matButton.disableRipple = false;
2077
- };
2078
- FsSubmitButtonDirective.prototype.error = function () {
2079
- this.setClass('error');
2080
- this._matButton.disableRipple = false;
2081
- };
2082
- FsSubmitButtonDirective.prototype.setClass = function (cls) {
2083
- var svg = this._getSvg(cls);
2084
- this._resetClass();
2085
- this._disableShadowAnimation();
2086
- this.element.classList.add("submit-" + cls);
2087
- this.element.append(svg);
2088
- };
2089
- Object.defineProperty(FsSubmitButtonDirective.prototype, "element", {
2090
- get: function () {
2091
- return this._elementRef.nativeElement;
2092
- },
2093
- enumerable: true,
2094
- configurable: true
2095
- });
2096
- FsSubmitButtonDirective.prototype.reset = function () {
2097
- this.active = false;
2098
- this.enable();
2099
- this.element.querySelectorAll('.svg-icon')
2100
- .forEach(function (el) {
2101
- el.remove();
2102
- });
2103
- this._matButton.disableRipple = false;
2104
- this._resetClass();
2105
- };
2106
- FsSubmitButtonDirective.prototype.ngOnDestroy = function () {
2107
- this._destroy$.next();
2108
- this._destroy$.complete();
2109
- this._form.removeSubmitButton(this);
2110
- };
2111
- FsSubmitButtonDirective.prototype._disableShadowAnimation = function () {
2112
- // .mat-elevation-z2 removes the click shadow animation
2113
- //this.element.classList.add('mat-elevation-z2');
2114
- };
2115
- FsSubmitButtonDirective.prototype._resetClass = function () {
2116
- this.element.classList.remove('submit-success', 'submit-error', 'submit-process', 'mat-elevation-z2');
2117
- };
2118
- FsSubmitButtonDirective.prototype._getSvg = function (type) {
2119
- if (type === 'success') {
2120
- 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;
2121
- }
2122
- if (type === 'process') {
2123
- 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;
2124
- }
2125
- if (type === 'error') {
2126
- 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;
2127
- }
2128
- };
2129
- FsSubmitButtonDirective.ctorParameters = function () { return [
2130
- { type: MatButton, decorators: [{ type: Optional }, { type: Host }] },
2131
- { type: FsFormDirective, decorators: [{ type: Optional }] },
2132
- { type: ElementRef },
2133
- { type: ChangeDetectorRef }
2134
- ]; };
2135
- __decorate([
2136
- Input(),
2137
- __metadata("design:type", Object)
2138
- ], FsSubmitButtonDirective.prototype, "name", void 0);
2139
- __decorate([
2140
- Input(),
2141
- __metadata("design:type", Object)
2142
- ], FsSubmitButtonDirective.prototype, "dirtySubmit", void 0);
2143
- __decorate([
2144
- HostBinding('style.transition'),
2145
- __metadata("design:type", Object)
2146
- ], FsSubmitButtonDirective.prototype, "transitionStyle", void 0);
2147
- FsSubmitButtonDirective = __decorate([
2148
- Directive({
2149
- selector: 'button[type="submit"]',
2150
- }),
2151
- __param(0, Optional()), __param(0, Host()),
2152
- __param(1, Optional()),
2153
- __metadata("design:paramtypes", [MatButton,
2154
- FsFormDirective,
2155
- ElementRef,
2156
- ChangeDetectorRef])
2157
- ], FsSubmitButtonDirective);
2158
- return FsSubmitButtonDirective;
2159
- }());
2160
-
2161
- var FsFormValidateDirective = /** @class */ (function (_super) {
2162
- __extends(FsFormValidateDirective, _super);
2163
- function FsFormValidateDirective() {
2164
- return _super !== null && _super.apply(this, arguments) || this;
2165
- }
2166
- FsFormValidateDirective.prototype.ngOnChanges = function () {
2167
- this._control.updateValueAndValidity();
2168
- };
2169
- FsFormValidateDirective.prototype.validateAsync = function (control) {
2170
- return FsValidators.func(this._control, this.validateFn, this.validateFnData);
2171
- };
2172
- __decorate([
2173
- Input('validate'),
2174
- __metadata("design:type", Object)
2175
- ], FsFormValidateDirective.prototype, "validateFn", void 0);
2176
- __decorate([
2177
- Input('validateData'),
2178
- __metadata("design:type", Object)
2179
- ], FsFormValidateDirective.prototype, "validateFnData", void 0);
2180
- FsFormValidateDirective = __decorate([
2181
- Directive({
2182
- selector: '[validate]',
2183
- providers: [
2184
- VALIDATE_MESSAGE_PROVIDER
2185
- ],
2186
- })
2187
- ], FsFormValidateDirective);
2188
- return FsFormValidateDirective;
2189
- }(FsControlDirective));
2190
-
2191
- var FsFormDialogActionsComponent = /** @class */ (function () {
2192
- function FsFormDialogActionsComponent(_form, _dialogRef, _cdRef) {
2193
- this._form = _form;
2194
- this._dialogRef = _dialogRef;
2195
- this._cdRef = _cdRef;
2196
- this.save = true;
2197
- this.create = false;
2198
- this.close = false;
2199
- this.dirty = false;
2200
- this._destroy$ = new Subject();
2201
- }
2202
- FsFormDialogActionsComponent.prototype.ngOnInit = function () {
2203
- var _this = this;
2204
- if (this._form) {
2205
- this._form.ngForm.valueChanges
2206
- .pipe(filter(function () { return (!_this.dirty); }), takeUntil(this._destroy$))
2207
- .subscribe(function () {
2208
- _this.dirty = _this._form.ngForm.dirty;
2209
- _this._cdRef.markForCheck();
2210
- });
2211
- this._form.submitted
2212
- .pipe(delay(50), takeUntil(this._destroy$))
2213
- .subscribe(function () {
2214
- _this.dirty = false;
2215
- _this._cdRef.markForCheck();
2216
- });
2217
- this._form.reseted
2218
- .pipe(takeUntil(this._destroy$))
2219
- .subscribe(function () {
2220
- _this.dirty = false;
2221
- _this._cdRef.markForCheck();
2222
- });
2223
- }
2224
- };
2225
- FsFormDialogActionsComponent.prototype.closeClick = function () {
2226
- var _this = this;
2227
- if (this._form) {
2228
- this._form.triggerConfirm()
2229
- .pipe(filter(function (confirmResult) { return (confirmResult !== ConfirmResult.Review); }), takeUntil(this._destroy$))
2230
- .subscribe(function () {
2231
- _this._dialogRef.close(null);
2232
- });
2233
- }
2234
- else {
2235
- this._dialogRef.close(null);
2236
- }
2237
- };
2238
- FsFormDialogActionsComponent.prototype.ngOnDestroy = function () {
2239
- this._destroy$.next();
2240
- this._destroy$.complete();
2241
- };
2242
- FsFormDialogActionsComponent.ctorParameters = function () { return [
2243
- { type: FsFormDirective, decorators: [{ type: Optional }] },
2244
- { type: MatDialogRef, decorators: [{ type: Optional }] },
2245
- { type: ChangeDetectorRef }
2246
- ]; };
2247
- __decorate([
2248
- Input(),
2249
- __metadata("design:type", Object)
2250
- ], FsFormDialogActionsComponent.prototype, "save", void 0);
2251
- __decorate([
2252
- Input(),
2253
- __metadata("design:type", Object)
2254
- ], FsFormDialogActionsComponent.prototype, "create", void 0);
2255
- __decorate([
2256
- Input(),
2257
- __metadata("design:type", Object)
2258
- ], FsFormDialogActionsComponent.prototype, "close", void 0);
2259
- __decorate([
2260
- Input(),
2261
- __metadata("design:type", String)
2262
- ], FsFormDialogActionsComponent.prototype, "name", void 0);
2263
- FsFormDialogActionsComponent = __decorate([
2264
- Component({
2265
- selector: 'fs-form-dialog-actions',
2266
- 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>",
2267
- changeDetection: ChangeDetectionStrategy.OnPush,
2268
- 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}}"]
2269
- }),
2270
- __param(0, Optional()),
2271
- __param(1, Optional()),
2272
- __metadata("design:paramtypes", [FsFormDirective,
2273
- MatDialogRef,
2274
- ChangeDetectorRef])
2275
- ], FsFormDialogActionsComponent);
2276
- return FsFormDialogActionsComponent;
2277
- }());
2278
-
2279
- var FsFormModule = /** @class */ (function () {
2280
- function FsFormModule() {
2281
- }
2282
- FsFormModule_1 = FsFormModule;
2283
- FsFormModule.forRoot = function () {
2284
- return {
2285
- ngModule: FsFormModule_1,
2286
- };
2287
- };
2288
- var FsFormModule_1;
2289
- FsFormModule = FsFormModule_1 = __decorate([
2290
- NgModule({
2291
- imports: [
2292
- CommonModule,
2293
- FormsModule,
2294
- MatButtonModule,
2295
- MatDialogModule,
2296
- ],
2297
- declarations: [
2298
- FsFormDirective,
2299
- FsControlDirective,
2300
- FsFormRequiredDirective,
2301
- FsFormMinDirective,
2302
- FsFormMaxDirective,
2303
- FsFormMinLengthDirective,
2304
- FsFormMaxLengthDirective,
2305
- FsFormEmailDirective,
2306
- FsFormEmailsDirective,
2307
- FsFormPhoneDirective,
2308
- FsFormCompareDirective,
2309
- FsFormIntegerDirective,
2310
- FsFormNumericDirective,
2311
- FsFormPatternDirective,
2312
- FsFormFunctionDirective,
2313
- FsFormDateRangeDirective,
2314
- FsFormGreaterDirective,
2315
- FsFormLesserDirective,
2316
- FsFormUrlDirective,
2317
- FsFormDialogCloseDirective,
2318
- FsSubmitButtonDirective,
2319
- FsFormValidateDirective,
2320
- FsFormDialogActionsComponent,
2321
- ],
2322
- exports: [
2323
- FsFormDirective,
2324
- FsControlDirective,
2325
- FsFormRequiredDirective,
2326
- FsFormMinDirective,
2327
- FsFormMaxDirective,
2328
- FsFormMinLengthDirective,
2329
- FsFormMaxLengthDirective,
2330
- FsFormEmailDirective,
2331
- FsFormEmailsDirective,
2332
- FsFormPhoneDirective,
2333
- FsFormCompareDirective,
2334
- FsFormIntegerDirective,
2335
- FsFormNumericDirective,
2336
- FsFormPatternDirective,
2337
- FsFormFunctionDirective,
2338
- FsFormDateRangeDirective,
2339
- FsFormGreaterDirective,
2340
- FsFormLesserDirective,
2341
- FsFormUrlDirective,
2342
- FsFormDialogCloseDirective,
2343
- FsSubmitButtonDirective,
2344
- FsFormValidateDirective,
2345
- FsFormDialogActionsComponent,
2346
- ],
2347
- providers: [
2348
- {
2349
- provide: ErrorStateMatcher,
2350
- useClass: ShowOnDirtyErrorStateMatcher,
2351
- },
2352
- ],
2353
- })
2354
- ], FsFormModule);
2355
- return FsFormModule;
2356
- }());
2357
-
2358
- var FormDeactivateGuard = /** @class */ (function () {
2359
- function FormDeactivateGuard(_prompt) {
2360
- this._prompt = _prompt;
2361
- }
2362
- FormDeactivateGuard.prototype.canDeactivate = function (directive) {
2363
- if (!('getForm' in directive)) {
2364
- var error = "Directive " + directive.constructor.name + " does not property implement interface FormDeactivate";
2365
- console.error(error);
2366
- return of(true);
2367
- }
2368
- var form = directive.getForm();
2369
- if (!(form instanceof FsFormDirective)) {
2370
- var error = "Directive " + directive.constructor.name + ".getForm() does not return a valid FsFormDirective";
2371
- console.error(error);
2372
- return of(true);
2373
- }
2374
- return confirmUnsaved(form, this._prompt)
2375
- .pipe(map(function (result) {
2376
- return confirmResultContinue(result);
2377
- }));
2378
- };
2379
- FormDeactivateGuard.ctorParameters = function () { return [
2380
- { type: FsPrompt }
2381
- ]; };
2382
- FormDeactivateGuard.ɵprov = ɵɵdefineInjectable({ factory: function FormDeactivateGuard_Factory() { return new FormDeactivateGuard(ɵɵinject(FsPrompt)); }, token: FormDeactivateGuard, providedIn: "root" });
2383
- FormDeactivateGuard = __decorate([
2384
- Injectable({
2385
- providedIn: 'root'
2386
- }),
2387
- __metadata("design:paramtypes", [FsPrompt])
2388
- ], FormDeactivateGuard);
2389
- return FormDeactivateGuard;
2390
- }());
2391
-
2392
- // Modules
2393
-
2394
- /**
2395
- * Generated bundle index. Do not edit.
2396
- */
2397
-
2398
- 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 };
2399
- //# sourceMappingURL=firestitch-form.js.map