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