@firestitch/form 9.7.6 → 9.7.7

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