@klippa/ngx-enhancy-forms 2.2.0 → 3.0.0
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.
- package/bundles/klippa-ngx-enhancy-forms.umd.js +482 -412
- package/bundles/klippa-ngx-enhancy-forms.umd.js.map +1 -1
- package/bundles/klippa-ngx-enhancy-forms.umd.min.js +2 -3
- package/bundles/klippa-ngx-enhancy-forms.umd.min.js.map +1 -1
- package/esm2015/lib/form/form-element/form-element.component.js +3 -1
- package/esm2015/lib/form/form.component.js +70 -13
- package/esm2015/lib/ngx-enhancy-forms.module.js +25 -23
- package/fesm2015/klippa-ngx-enhancy-forms.js +110 -50
- package/fesm2015/klippa-ngx-enhancy-forms.js.map +1 -1
- package/klippa-ngx-enhancy-forms.metadata.json +1 -1
- package/lib/form/form.component.d.ts +18 -5
- package/package.json +1 -1
|
@@ -4,426 +4,76 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.klippa = global.klippa || {}, global.klippa["ngx-enhancy-forms"] = {}), global.ng.core, global.ng.common, global.ng.forms, global.lodash, global.ngxSortablejs, global.ngSelect, global.ng.material.core, global.ng.material.datepicker, global.ng.material.formField, global.ng.material.input, global.ng.material.button));
|
|
5
5
|
})(this, (function (exports, core, common, forms, lodash, ngxSortablejs, ngSelect, core$1, datepicker, formField, input, button) { 'use strict';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function FormComponent() {
|
|
10
|
-
// we keep track of what form controls are actually rendered. Only those count when looking at form validation
|
|
11
|
-
this.activeControls = [];
|
|
12
|
-
}
|
|
13
|
-
FormComponent.prototype.registerControl = function (formControl, formElement) {
|
|
14
|
-
this.activeControls.push({ formControl: formControl, formElement: formElement });
|
|
15
|
-
};
|
|
16
|
-
FormComponent.prototype.unregisterControl = function (formControl) {
|
|
17
|
-
this.activeControls = this.activeControls.filter(function (e) { return e.formControl !== formControl; });
|
|
18
|
-
};
|
|
19
|
-
FormComponent.prototype.disableInactiveFormGroupControls = function (formGroup) {
|
|
20
|
-
var _this = this;
|
|
21
|
-
Object.values(formGroup.controls).forEach(function (value) {
|
|
22
|
-
if (value instanceof forms.FormGroup) {
|
|
23
|
-
_this.disableInactiveFormGroupControls(value);
|
|
24
|
-
}
|
|
25
|
-
else if (value instanceof forms.FormArray) {
|
|
26
|
-
_this.disableInactiveFormArrayControls(value);
|
|
27
|
-
}
|
|
28
|
-
else if (value instanceof forms.FormControl) {
|
|
29
|
-
_this.disableInactiveFormControl(value);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
FormComponent.prototype.disableInactiveFormArrayControls = function (formArray) {
|
|
34
|
-
var _this = this;
|
|
35
|
-
formArray.controls.forEach(function (value) {
|
|
36
|
-
if (value instanceof forms.FormGroup) {
|
|
37
|
-
_this.disableInactiveFormGroupControls(value);
|
|
38
|
-
}
|
|
39
|
-
else if (value instanceof forms.FormArray) {
|
|
40
|
-
_this.disableInactiveFormArrayControls(value);
|
|
41
|
-
}
|
|
42
|
-
else if (value instanceof forms.FormControl) {
|
|
43
|
-
_this.disableInactiveFormControl(value);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
FormComponent.prototype.disableInactiveFormControl = function (control) {
|
|
48
|
-
if (!this.activeControls.some(function (e) { return e.formControl === control; })) {
|
|
49
|
-
control.disable();
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
FormComponent.prototype.trySubmit = function () {
|
|
53
|
-
var _a, _b;
|
|
54
|
-
this.formGroup.markAllAsTouched();
|
|
55
|
-
var originalDisabledStates = Object.values(this.formGroup.controls).map(function (e) {
|
|
56
|
-
return { control: e, disabled: e.disabled };
|
|
57
|
-
});
|
|
58
|
-
this.disableInactiveFormGroupControls(this.formGroup);
|
|
59
|
-
var values = this.formGroup.value;
|
|
60
|
-
if (this.formGroup.valid) {
|
|
61
|
-
this.setDisabledStatesForAllControls(originalDisabledStates);
|
|
62
|
-
return Promise.resolve(values);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
(_b = (_a = this.activeControls.find(function (e) { return !e.formControl.valid; })) === null || _a === void 0 ? void 0 : _a.formElement) === null || _b === void 0 ? void 0 : _b.scrollTo();
|
|
66
|
-
this.setDisabledStatesForAllControls(originalDisabledStates);
|
|
67
|
-
return Promise.reject(invalidFieldsSymbol);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
FormComponent.prototype.setDisabledStatesForAllControls = function (originalDisabledStates) {
|
|
71
|
-
originalDisabledStates.forEach(function (e) {
|
|
72
|
-
if (e.disabled) {
|
|
73
|
-
e.control.disable();
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
e.control.enable();
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
};
|
|
80
|
-
return FormComponent;
|
|
81
|
-
}());
|
|
82
|
-
FormComponent.decorators = [
|
|
83
|
-
{ type: core.Component, args: [{
|
|
84
|
-
selector: 'klp-form',
|
|
85
|
-
template: "<form>\n\t<ng-content></ng-content>\n</form>\n\n\n",
|
|
86
|
-
styles: [":host{display:block}:host.row{display:flex}"]
|
|
87
|
-
},] }
|
|
88
|
-
];
|
|
89
|
-
FormComponent.propDecorators = {
|
|
90
|
-
formGroup: [{ type: core.Input }]
|
|
91
|
-
};
|
|
7
|
+
/*! *****************************************************************************
|
|
8
|
+
Copyright (c) Microsoft Corporation.
|
|
92
9
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
10
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
+
purpose with or without fee is hereby granted.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
20
|
+
***************************************************************************** */
|
|
21
|
+
/* global Reflect, Promise */
|
|
22
|
+
var extendStatics = function (d, b) {
|
|
23
|
+
extendStatics = Object.setPrototypeOf ||
|
|
24
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
25
|
+
function (d, b) { for (var p in b)
|
|
26
|
+
if (Object.prototype.hasOwnProperty.call(b, p))
|
|
27
|
+
d[p] = b[p]; };
|
|
28
|
+
return extendStatics(d, b);
|
|
104
29
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
};
|
|
120
|
-
FormElementComponent.prototype.registerControl = function (formControl) {
|
|
121
|
-
this.attachedControl = formControl;
|
|
122
|
-
this.parent.registerControl(formControl, this);
|
|
123
|
-
};
|
|
124
|
-
FormElementComponent.prototype.unregisterControl = function (formControl) {
|
|
125
|
-
this.attachedControl = null;
|
|
126
|
-
this.parent.unregisterControl(formControl);
|
|
127
|
-
};
|
|
128
|
-
FormElementComponent.prototype.getAttachedControl = function () {
|
|
129
|
-
return this.attachedControl;
|
|
130
|
-
};
|
|
131
|
-
FormElementComponent.prototype.registerErrorHandler = function (error, templateRef) {
|
|
132
|
-
this.customErrorHandlers.push({ error: error, templateRef: templateRef });
|
|
133
|
-
};
|
|
134
|
-
FormElementComponent.prototype.registerCaption = function (templateRef) {
|
|
135
|
-
this.captionRef = templateRef;
|
|
136
|
-
};
|
|
137
|
-
FormElementComponent.prototype.getErrorToShow = function () {
|
|
138
|
-
var _a, _b, _c;
|
|
139
|
-
if (((_a = this.attachedControl) === null || _a === void 0 ? void 0 : _a.touched) === true && ((_b = this.attachedControl) === null || _b === void 0 ? void 0 : _b.errors)) {
|
|
140
|
-
return Object.keys((_c = this.attachedControl) === null || _c === void 0 ? void 0 : _c.errors)[0];
|
|
141
|
-
}
|
|
142
|
-
return null;
|
|
143
|
-
};
|
|
144
|
-
FormElementComponent.prototype.getCustomErrorHandler = function (error) {
|
|
145
|
-
return this.customErrorHandlers.find(function (e) { return e.error === error; });
|
|
146
|
-
};
|
|
147
|
-
FormElementComponent.prototype.showDefaultError = function (error) {
|
|
148
|
-
return this.getErrorToShow() === error && !this.customErrorHandlers.some(function (e) { return e.error === error; });
|
|
149
|
-
};
|
|
150
|
-
FormElementComponent.prototype.getScrollableParent = function (node) {
|
|
151
|
-
if (node == null) {
|
|
152
|
-
return null;
|
|
153
|
-
}
|
|
154
|
-
if (node.scrollHeight > node.clientHeight) {
|
|
155
|
-
return node;
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
return this.getScrollableParent(node.parentNode);
|
|
30
|
+
function __extends(d, b) {
|
|
31
|
+
if (typeof b !== "function" && b !== null)
|
|
32
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
33
|
+
extendStatics(d, b);
|
|
34
|
+
function __() { this.constructor = d; }
|
|
35
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
36
|
+
}
|
|
37
|
+
var __assign = function () {
|
|
38
|
+
__assign = Object.assign || function __assign(t) {
|
|
39
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
40
|
+
s = arguments[i];
|
|
41
|
+
for (var p in s)
|
|
42
|
+
if (Object.prototype.hasOwnProperty.call(s, p))
|
|
43
|
+
t[p] = s[p];
|
|
159
44
|
}
|
|
45
|
+
return t;
|
|
160
46
|
};
|
|
161
|
-
|
|
162
|
-
var _a;
|
|
163
|
-
this.internalComponentRef.nativeElement.scrollIntoView(true);
|
|
164
|
-
// to give some breathing room, we scroll 100px more to the top
|
|
165
|
-
(_a = this.getScrollableParent(this.internalComponentRef.nativeElement)) === null || _a === void 0 ? void 0 : _a.scrollBy(0, -100);
|
|
166
|
-
};
|
|
167
|
-
FormElementComponent.prototype.getErrorMessages = function (key) {
|
|
168
|
-
var _a, _b, _c;
|
|
169
|
-
return (_c = (_b = (_a = this.customMessages) === null || _a === void 0 ? void 0 : _a[key]) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : this.errorMessages[key];
|
|
170
|
-
};
|
|
171
|
-
return FormElementComponent;
|
|
172
|
-
}());
|
|
173
|
-
FormElementComponent.decorators = [
|
|
174
|
-
{ type: core.Component, args: [{
|
|
175
|
-
selector: 'klp-form-element',
|
|
176
|
-
template: "<ng-template #errorRef>\n\t<div *ngIf=\"getErrorToShow()\" class=\"errorContainer\">\n\t\t<div *ngIf=\"showDefaultError('min')\">{{substituteParameters(getErrorMessages(\"min\"), {min: attachedControl.errors.min.min})}}</div>\n\t\t<div *ngIf=\"showDefaultError('max')\">{{substituteParameters(getErrorMessages(\"max\"), {max: attachedControl.errors.max.max})}}</div>\n\t\t<div *ngIf=\"showDefaultError('required')\">{{getErrorMessages(\"required\")}}</div>\n\t\t<div *ngIf=\"showDefaultError('email')\">{{getErrorMessages(\"email\")}}</div>\n\t\t<div *ngIf=\"showDefaultError('minlength')\">{{substituteParameters(getErrorMessages(\"minLength\"), {minLength: attachedControl.errors.minlength.requiredLength})}}</div>\n\t\t<div *ngIf=\"showDefaultError('maxlength')\">{{substituteParameters(getErrorMessages(\"maxLength\"), {maxLength: attachedControl.errors.maxlength.requiredLength})}}</div>\n\t\t<div *ngIf=\"showDefaultError('pattern')\">{{getErrorMessages(\"pattern\")}}</div>\n\t\t<div *ngIf=\"showDefaultError('MatchPassword')\">{{getErrorMessages(\"matchPassword\")}}</div>\n\t\t<div *ngIf=\"showDefaultError('date')\">{{getErrorMessages(\"date\")}}</div>\n\t\t<div *ngIf=\"showDefaultError('message')\">{{attachedControl.errors.message.value}}</div>\n\t\t<div [ngTemplateOutlet]=\"getCustomErrorHandler(getErrorToShow())?.templateRef\"></div>\n\t</div>\n</ng-template>\n<ng-container *ngIf=\"direction === 'horizontal'\" [ngTemplateOutlet]=\"errorRef\"></ng-container>\n<div *ngIf=\"attachedControl\" class=\"componentContainer\" [ngClass]=\"{vertical: direction === 'vertical', reverseOrder: swapInputAndCaption}\" #internalComponentRef>\n\t<div class=\"caption\" [ngClass]=\"{ hasErrors: getErrorToShow() && attachedControl.touched, percentageSpacing: captionSpacing === 'percentages' }\">\n\t\t<div *ngIf=\"captionRef\" [ngTemplateOutlet]=\"captionRef\"></div>\n\t\t<div *ngIf=\"!captionRef\">{{caption}}</div>\n\t</div>\n\t<ng-container *ngIf=\"direction === 'vertical'\" [ngTemplateOutlet]=\"errorRef\"></ng-container>\n\t<div class=\"inputContainer\" [ngClass]=\"{ percentageSpacing: captionSpacing === 'percentages' }\">\n\t\t<ng-content></ng-content>\n\t</div>\n</div>\n",
|
|
177
|
-
styles: [":host{display:block;margin-top:1.25rem}.componentContainer{align-items:center;display:flex}.componentContainer.reverseOrder{flex-direction:row-reverse;justify-content:flex-end}.componentContainer.vertical{display:block;margin-bottom:1rem}.componentContainer.vertical .inputContainer{margin-top:.3125rem}.componentContainer.vertical .errorContainer{margin-left:0}.caption{color:#515365;flex:0 0 auto;font-weight:700}.caption.percentageSpacing{flex:0 0 40%}.caption.hasErrors{color:#ff8000}.inputContainer{flex:0 0 auto}.inputContainer.percentageSpacing{flex:0 0 60%}.errorContainer{color:#ff8000;margin-left:40%}"]
|
|
178
|
-
},] }
|
|
179
|
-
];
|
|
180
|
-
FormElementComponent.ctorParameters = function () { return [
|
|
181
|
-
{ type: FormComponent, decorators: [{ type: core.Host }, { type: core.Optional }] },
|
|
182
|
-
{ type: undefined, decorators: [{ type: core.Inject, args: [FORM_ERROR_MESSAGES,] }, { type: core.Optional }] }
|
|
183
|
-
]; };
|
|
184
|
-
FormElementComponent.propDecorators = {
|
|
185
|
-
caption: [{ type: core.Input }],
|
|
186
|
-
direction: [{ type: core.Input }],
|
|
187
|
-
captionSpacing: [{ type: core.Input }],
|
|
188
|
-
swapInputAndCaption: [{ type: core.Input }],
|
|
189
|
-
internalComponentRef: [{ type: core.ViewChild, args: ['internalComponentRef',] }]
|
|
47
|
+
return __assign.apply(this, arguments);
|
|
190
48
|
};
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
return value !== null && value !== undefined;
|
|
49
|
+
function __rest(s, e) {
|
|
50
|
+
var t = {};
|
|
51
|
+
for (var p in s)
|
|
52
|
+
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
53
|
+
t[p] = s[p];
|
|
54
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
55
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
56
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
57
|
+
t[p[i]] = s[p[i]];
|
|
58
|
+
}
|
|
59
|
+
return t;
|
|
203
60
|
}
|
|
204
|
-
function
|
|
205
|
-
|
|
61
|
+
function __decorate(decorators, target, key, desc) {
|
|
62
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
63
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
64
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
65
|
+
else
|
|
66
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
67
|
+
if (d = decorators[i])
|
|
68
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
69
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
206
70
|
}
|
|
207
|
-
function
|
|
208
|
-
|
|
209
|
-
return s;
|
|
210
|
-
}
|
|
211
|
-
return undefined;
|
|
71
|
+
function __param(paramIndex, decorator) {
|
|
72
|
+
return function (target, key) { decorator(target, key, paramIndex); };
|
|
212
73
|
}
|
|
213
|
-
function
|
|
214
|
-
if (
|
|
215
|
-
return
|
|
216
|
-
}
|
|
217
|
-
return undefined;
|
|
218
|
-
}
|
|
219
|
-
function convertParentToChild(originalClass, newClass) {
|
|
220
|
-
return Object.assign(newClass, originalClass);
|
|
221
|
-
}
|
|
222
|
-
function truncateString(s, length) {
|
|
223
|
-
if (s.length < length) {
|
|
224
|
-
return s;
|
|
225
|
-
}
|
|
226
|
-
return s.substring(0, length) + '...';
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* This component is a base in order to create a component that supports ngModel.
|
|
231
|
-
* Some important things to know about it:
|
|
232
|
-
*
|
|
233
|
-
* innerValue = your own inner state, which you should use to store the current state of what ngModel should be.
|
|
234
|
-
* writeValue() = called by angular, when ngModel is changed from OUTSIDE of the component. Feel free to patch this method if you need inner logic to happen when ngModel is altered from the outside. Always remember to also call the super.writeValue if you do!
|
|
235
|
-
* setInnerValueAndNotify() = call this when you want your ngModel to be updated from INSIDE of your component, and provide it to the OUTSIDE.
|
|
236
|
-
* ngOnInit() = Used to support the angular reactive forms framework. If you use ngOnInit in your own component (which happens fairly often) you must not forget to call the super.ngOnInit() method.
|
|
237
|
-
*/
|
|
238
|
-
var ValueAccessorBase = /** @class */ (function () {
|
|
239
|
-
function ValueAccessorBase(parent, controlContainer) {
|
|
240
|
-
this.parent = parent;
|
|
241
|
-
this.controlContainer = controlContainer;
|
|
242
|
-
this.changed = new Array();
|
|
243
|
-
this.touched = new Array();
|
|
244
|
-
this.disabled = false;
|
|
245
|
-
// we support both providing just the formControlName and the full formControl
|
|
246
|
-
this.formControlName = null;
|
|
247
|
-
this.formControl = null;
|
|
248
|
-
}
|
|
249
|
-
ValueAccessorBase.prototype.ngOnInit = function () {
|
|
250
|
-
var _this = this;
|
|
251
|
-
var _a, _b, _c;
|
|
252
|
-
if (this.formControl) {
|
|
253
|
-
this.attachedFormControl = this.formControl;
|
|
254
|
-
}
|
|
255
|
-
else if (stringIsSetAndNotEmpty(this.formControlName)) {
|
|
256
|
-
this.attachedFormControl = (_a = this.controlContainer) === null || _a === void 0 ? void 0 : _a.control.get(this.formControlName);
|
|
257
|
-
if (isNullOrUndefined(this.attachedFormControl)) {
|
|
258
|
-
throw new Error("Form element '" + this.formControlName + "' with caption '" + ((_b = this.parent) === null || _b === void 0 ? void 0 : _b.caption) + "' is not declared in your FormGroup.");
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
if (this.attachedFormControl) {
|
|
262
|
-
this.disabled = this.attachedFormControl.disabled;
|
|
263
|
-
this.attachedFormControl.statusChanges.subscribe(function () {
|
|
264
|
-
_this.disabled = _this.attachedFormControl.disabled;
|
|
265
|
-
});
|
|
266
|
-
(_c = this.parent) === null || _c === void 0 ? void 0 : _c.registerControl(this.attachedFormControl);
|
|
267
|
-
}
|
|
268
|
-
};
|
|
269
|
-
ValueAccessorBase.prototype.isInErrorState = function () {
|
|
270
|
-
return this.attachedFormControl && this.attachedFormControl.status === 'INVALID' && this.attachedFormControl.touched;
|
|
271
|
-
};
|
|
272
|
-
ValueAccessorBase.prototype.ngOnDestroy = function () {
|
|
273
|
-
var _a;
|
|
274
|
-
if (this.attachedFormControl) {
|
|
275
|
-
(_a = this.parent) === null || _a === void 0 ? void 0 : _a.unregisterControl(this.attachedFormControl);
|
|
276
|
-
}
|
|
277
|
-
};
|
|
278
|
-
ValueAccessorBase.prototype.touch = function () {
|
|
279
|
-
this.touched.forEach(function (f) { return f(); });
|
|
280
|
-
};
|
|
281
|
-
ValueAccessorBase.prototype.writeValue = function (value) {
|
|
282
|
-
this.innerValue = value;
|
|
283
|
-
};
|
|
284
|
-
ValueAccessorBase.prototype.registerOnChange = function (fn) {
|
|
285
|
-
this.changed.push(fn);
|
|
286
|
-
};
|
|
287
|
-
ValueAccessorBase.prototype.registerOnTouched = function (fn) {
|
|
288
|
-
this.touched.push(fn);
|
|
289
|
-
};
|
|
290
|
-
ValueAccessorBase.prototype.setInnerValueAndNotify = function (value) {
|
|
291
|
-
this.innerValue = value;
|
|
292
|
-
this.changed.forEach(function (fn) { return fn(value); });
|
|
293
|
-
};
|
|
294
|
-
ValueAccessorBase.prototype.resetToNull = function () {
|
|
295
|
-
this.setInnerValueAndNotify(null);
|
|
296
|
-
};
|
|
297
|
-
return ValueAccessorBase;
|
|
298
|
-
}());
|
|
299
|
-
ValueAccessorBase.decorators = [
|
|
300
|
-
{ type: core.Component, args: [{
|
|
301
|
-
selector: '',
|
|
302
|
-
template: ''
|
|
303
|
-
},] }
|
|
304
|
-
];
|
|
305
|
-
ValueAccessorBase.ctorParameters = function () { return [
|
|
306
|
-
{ type: FormElementComponent, decorators: [{ type: core.Host }, { type: core.Optional }] },
|
|
307
|
-
{ type: forms.ControlContainer, decorators: [{ type: core.Host }, { type: core.Optional }] }
|
|
308
|
-
]; };
|
|
309
|
-
ValueAccessorBase.propDecorators = {
|
|
310
|
-
disabled: [{ type: core.Input }],
|
|
311
|
-
formControlName: [{ type: core.Input }],
|
|
312
|
-
formControl: [{ type: core.Input }]
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
var ButtonComponent = /** @class */ (function () {
|
|
316
|
-
function ButtonComponent() {
|
|
317
|
-
this.variant = 'white';
|
|
318
|
-
this.size = 'medium';
|
|
319
|
-
this.fullWidth = false;
|
|
320
|
-
this.hasBorder = true;
|
|
321
|
-
this.disabled = false;
|
|
322
|
-
this.isLoading = false;
|
|
323
|
-
this.type = 'button';
|
|
324
|
-
}
|
|
325
|
-
Object.defineProperty(ButtonComponent.prototype, "_", {
|
|
326
|
-
get: function () {
|
|
327
|
-
return this.fullWidth;
|
|
328
|
-
},
|
|
329
|
-
enumerable: false,
|
|
330
|
-
configurable: true
|
|
331
|
-
});
|
|
332
|
-
ButtonComponent.prototype.onClick = function (event) {
|
|
333
|
-
if (this.disabled) {
|
|
334
|
-
event.stopPropagation();
|
|
335
|
-
}
|
|
336
|
-
};
|
|
337
|
-
return ButtonComponent;
|
|
338
|
-
}());
|
|
339
|
-
ButtonComponent.decorators = [
|
|
340
|
-
{ type: core.Component, args: [{
|
|
341
|
-
selector: 'klp-form-button',
|
|
342
|
-
template: "<button class=\"buttonFundamentals\"\n\t[ngClass]=\"[\n\t\tvariant,\n\t\tsize,\n\t\tfullWidth ? 'fullWidth' : '',\n\t\thasBorder ? '' : 'no-border',\n\t\tdisabled ? 'disabled' : ''\n\t]\"\n\t[type]=\"type\"\n\t(click)=\"onClick($event)\"\n>\n\t<div class=\"caption\" [ngClass]=\"{invisible: isLoading}\">\n\t\t<ng-content></ng-content>\n\t</div>\n\t<div class=\"loadingSpinnerContainer\" *ngIf=\"isLoading\">\n\t\t<klp-form-loading-indicator variant=\"spinner\" size=\"small\"></klp-form-loading-indicator>\n\t</div>\n</button>\n",
|
|
343
|
-
styles: [":host{display:inline-block}:host._fullWidth{display:block}.buttonFundamentals{border:1px solid #e6ecf5;border-radius:5px;color:#888da8;cursor:pointer;font-size:13px;font-weight:700;letter-spacing:1px;padding:10px 20px}.fullWidth{width:100%}.no-border{border:none}.caption.invisible{visibility:hidden}button{position:relative}.loadingSpinnerContainer{align-items:center;bottom:0;display:flex;justify-content:center;left:0;position:absolute;right:0;top:0}.small{padding-bottom:.375rem;padding-top:.375rem}.large{line-height:2}.white{background-color:#fff;border-color:#d4deee;color:#515365;font-weight:500}.white:active,.white:hover{background-color:#edf2f8;border-color:#edf2f8;color:#515365}.white:focus{text-decoration:underline}.greenFilled{background-color:#27bb5f;border-color:#27bb5f;color:#fff}.greenFilled:hover{background-color:#2bd06a;border-color:#2bd06a;color:#fff}.greenFilled:focus{text-decoration:underline}.greenFilled:active{background-color:#23a654;border-color:#23a654}.greenOutlined{background-color:#fff;border-color:#27bb5f;color:#27bb5f}.greenOutlined:hover{background-color:#2bd06a;border-color:#2bd06a;color:#fff}.greenOutlined:focus{text-decoration:underline}.greenOutlined:active{background-color:#23a654;border-color:#23a654}.greenLink{background:none;border:none;color:#27bb5f;padding:0}.greenLink:focus,.greenLink:hover{text-decoration:underline}.contextMenuItem{background-color:#fff;border-color:#fff;color:#888da8}.contextMenuItem:hover{background-color:#f6f7fb;border-color:#f6f7fb}.contextMenuItem:active,.contextMenuItem:focus{text-decoration:underline}.redFilled{background-color:#ff3c7e;border-color:#ff3c7e;color:#fff}.redFilled:hover{background-color:#ff568f;border-color:#ff568f;color:#fff}.redFilled:focus{text-decoration:underline}.redFilled:active{background-color:#ff236d;border-color:#ff236d}.redOutlined{background-color:#fff;border-color:#ff3c7e;color:#ff3c7e}.redOutlined:hover{background-color:#ff568f;border-color:#ff568f;color:#fff}.redOutlined:focus{text-decoration:underline}.redOutlined:active{background-color:#ff236d;border-color:#ff236d}.orangeFilled{background-color:#ff8000;border-color:#ff8000;color:#fff}.orangeFilled:hover{background-color:#ff8d1a;border-color:#ff8d1a;color:#fff}.orangeFilled:focus{text-decoration:underline}.orangeFilled:active{background-color:#e67300;border-color:#e67300}"]
|
|
344
|
-
},] }
|
|
345
|
-
];
|
|
346
|
-
ButtonComponent.propDecorators = {
|
|
347
|
-
variant: [{ type: core.Input }],
|
|
348
|
-
size: [{ type: core.Input }],
|
|
349
|
-
fullWidth: [{ type: core.Input }],
|
|
350
|
-
hasBorder: [{ type: core.Input }],
|
|
351
|
-
disabled: [{ type: core.Input }],
|
|
352
|
-
isLoading: [{ type: core.Input }],
|
|
353
|
-
type: [{ type: core.Input }],
|
|
354
|
-
_: [{ type: core.HostBinding, args: ['class._fullWidth',] }]
|
|
355
|
-
};
|
|
356
|
-
|
|
357
|
-
/*! *****************************************************************************
|
|
358
|
-
Copyright (c) Microsoft Corporation.
|
|
359
|
-
|
|
360
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
361
|
-
purpose with or without fee is hereby granted.
|
|
362
|
-
|
|
363
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
364
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
365
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
366
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
367
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
368
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
369
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
370
|
-
***************************************************************************** */
|
|
371
|
-
/* global Reflect, Promise */
|
|
372
|
-
var extendStatics = function (d, b) {
|
|
373
|
-
extendStatics = Object.setPrototypeOf ||
|
|
374
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
375
|
-
function (d, b) { for (var p in b)
|
|
376
|
-
if (Object.prototype.hasOwnProperty.call(b, p))
|
|
377
|
-
d[p] = b[p]; };
|
|
378
|
-
return extendStatics(d, b);
|
|
379
|
-
};
|
|
380
|
-
function __extends(d, b) {
|
|
381
|
-
if (typeof b !== "function" && b !== null)
|
|
382
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
383
|
-
extendStatics(d, b);
|
|
384
|
-
function __() { this.constructor = d; }
|
|
385
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
386
|
-
}
|
|
387
|
-
var __assign = function () {
|
|
388
|
-
__assign = Object.assign || function __assign(t) {
|
|
389
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
390
|
-
s = arguments[i];
|
|
391
|
-
for (var p in s)
|
|
392
|
-
if (Object.prototype.hasOwnProperty.call(s, p))
|
|
393
|
-
t[p] = s[p];
|
|
394
|
-
}
|
|
395
|
-
return t;
|
|
396
|
-
};
|
|
397
|
-
return __assign.apply(this, arguments);
|
|
398
|
-
};
|
|
399
|
-
function __rest(s, e) {
|
|
400
|
-
var t = {};
|
|
401
|
-
for (var p in s)
|
|
402
|
-
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
403
|
-
t[p] = s[p];
|
|
404
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
405
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
406
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
407
|
-
t[p[i]] = s[p[i]];
|
|
408
|
-
}
|
|
409
|
-
return t;
|
|
410
|
-
}
|
|
411
|
-
function __decorate(decorators, target, key, desc) {
|
|
412
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
413
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
414
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
415
|
-
else
|
|
416
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
417
|
-
if (d = decorators[i])
|
|
418
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
419
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
420
|
-
}
|
|
421
|
-
function __param(paramIndex, decorator) {
|
|
422
|
-
return function (target, key) { decorator(target, key, paramIndex); };
|
|
423
|
-
}
|
|
424
|
-
function __metadata(metadataKey, metadataValue) {
|
|
425
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
426
|
-
return Reflect.metadata(metadataKey, metadataValue);
|
|
74
|
+
function __metadata(metadataKey, metadataValue) {
|
|
75
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
76
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
427
77
|
}
|
|
428
78
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
429
79
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -672,6 +322,422 @@
|
|
|
672
322
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
673
323
|
}
|
|
674
324
|
|
|
325
|
+
function stringIsSetAndNotEmpty(s) {
|
|
326
|
+
return lodash.isString(s) && s.length > 0;
|
|
327
|
+
}
|
|
328
|
+
function isNullOrUndefined(value) {
|
|
329
|
+
return value === null || value === undefined;
|
|
330
|
+
}
|
|
331
|
+
function numberIsSet(value) {
|
|
332
|
+
return isValueSet(value) && typeof value === 'number';
|
|
333
|
+
}
|
|
334
|
+
function isValueSet(value) {
|
|
335
|
+
return value !== null && value !== undefined;
|
|
336
|
+
}
|
|
337
|
+
function stringOrArrayIsSetAndEmpty(value) {
|
|
338
|
+
return value !== null && value !== undefined && value.length === 0;
|
|
339
|
+
}
|
|
340
|
+
function useIfStringIsSet(s) {
|
|
341
|
+
if (stringIsSetAndNotEmpty(s)) {
|
|
342
|
+
return s;
|
|
343
|
+
}
|
|
344
|
+
return undefined;
|
|
345
|
+
}
|
|
346
|
+
function useIfArrayIsSetWithOneItem(a) {
|
|
347
|
+
if (!isNullOrUndefined(a) && a.length === 1) {
|
|
348
|
+
return a[0];
|
|
349
|
+
}
|
|
350
|
+
return undefined;
|
|
351
|
+
}
|
|
352
|
+
function convertParentToChild(originalClass, newClass) {
|
|
353
|
+
return Object.assign(newClass, originalClass);
|
|
354
|
+
}
|
|
355
|
+
function truncateString(s, length) {
|
|
356
|
+
if (s.length < length) {
|
|
357
|
+
return s;
|
|
358
|
+
}
|
|
359
|
+
return s.substring(0, length) + '...';
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
var invalidFieldsSymbol = Symbol('Not all fields are valid');
|
|
363
|
+
var SubFormDirective = /** @class */ (function () {
|
|
364
|
+
function SubFormDirective() {
|
|
365
|
+
}
|
|
366
|
+
return SubFormDirective;
|
|
367
|
+
}());
|
|
368
|
+
SubFormDirective.decorators = [
|
|
369
|
+
{ type: core.Directive, args: [{
|
|
370
|
+
// tslint:disable-next-line:directive-selector
|
|
371
|
+
selector: 'klp-sub-form',
|
|
372
|
+
},] }
|
|
373
|
+
];
|
|
374
|
+
SubFormDirective.propDecorators = {
|
|
375
|
+
injectInto: [{ type: core.Input }]
|
|
376
|
+
};
|
|
377
|
+
// Only used as a 'marker' to define a property will be filled in by a sub form
|
|
378
|
+
var SubForm = /** @class */ (function (_super) {
|
|
379
|
+
__extends(SubForm, _super);
|
|
380
|
+
function SubForm() {
|
|
381
|
+
return _super.call(this, {}, null) || this;
|
|
382
|
+
}
|
|
383
|
+
return SubForm;
|
|
384
|
+
}(forms.FormGroup));
|
|
385
|
+
var FormComponent = /** @class */ (function () {
|
|
386
|
+
function FormComponent(parent, subFormPlaceholder) {
|
|
387
|
+
this.parent = parent;
|
|
388
|
+
this.subFormPlaceholder = subFormPlaceholder;
|
|
389
|
+
// we keep track of what form controls are actually rendered. Only those count when looking at form validation
|
|
390
|
+
this.activeControls = [];
|
|
391
|
+
}
|
|
392
|
+
FormComponent.prototype.ngOnInit = function () {
|
|
393
|
+
var _this = this;
|
|
394
|
+
if (isValueSet(this.parent) && isValueSet(this.subFormPlaceholder)) {
|
|
395
|
+
var parentOfInjectInto = this.subFormPlaceholder.injectInto.parent;
|
|
396
|
+
if (parentOfInjectInto instanceof forms.FormArray) {
|
|
397
|
+
var i = parentOfInjectInto.controls.findIndex(function (e) { return e === _this.subFormPlaceholder.injectInto; });
|
|
398
|
+
parentOfInjectInto.setControl(i, this.formGroup);
|
|
399
|
+
}
|
|
400
|
+
else if (parentOfInjectInto instanceof forms.FormGroup) {
|
|
401
|
+
var toReplace = Object.entries(parentOfInjectInto.controls).find(function (_c) {
|
|
402
|
+
var _d = __read(_c, 2), key = _d[0], val = _d[1];
|
|
403
|
+
return val === _this.subFormPlaceholder.injectInto;
|
|
404
|
+
});
|
|
405
|
+
if (!((toReplace === null || toReplace === void 0 ? void 0 : toReplace[1]) instanceof SubForm)) {
|
|
406
|
+
throw new Error("You are trying to inject a subForm ('" + (toReplace === null || toReplace === void 0 ? void 0 : toReplace[0]) + "') within something that is not annotated as such.");
|
|
407
|
+
}
|
|
408
|
+
parentOfInjectInto.setControl(toReplace[0], this.formGroup);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
FormComponent.prototype.registerControl = function (formControl, formElement) {
|
|
413
|
+
this.activeControls.push({ formControl: formControl, formElement: formElement });
|
|
414
|
+
if (this.parent) {
|
|
415
|
+
this.parent.registerControl(formControl, formElement);
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
FormComponent.prototype.unregisterControl = function (formControl) {
|
|
419
|
+
this.activeControls = this.activeControls.filter(function (e) { return e.formControl !== formControl; });
|
|
420
|
+
if (this.parent) {
|
|
421
|
+
this.parent.unregisterControl(formControl);
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
FormComponent.prototype.addFormGroupControls = function (formGroup, result) {
|
|
425
|
+
var _this = this;
|
|
426
|
+
Object.values(formGroup.controls).forEach(function (value) {
|
|
427
|
+
if (value instanceof forms.FormGroup) {
|
|
428
|
+
_this.addFormGroupControls(value, result);
|
|
429
|
+
}
|
|
430
|
+
else if (value instanceof forms.FormArray) {
|
|
431
|
+
_this.addFormArrayControls(value, result);
|
|
432
|
+
}
|
|
433
|
+
else if (value instanceof forms.FormControl) {
|
|
434
|
+
_this.addFormControl(value, result);
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
};
|
|
438
|
+
FormComponent.prototype.addFormArrayControls = function (formArray, result) {
|
|
439
|
+
var _this = this;
|
|
440
|
+
formArray.controls.forEach(function (value) {
|
|
441
|
+
if (value instanceof forms.FormGroup) {
|
|
442
|
+
_this.addFormGroupControls(value, result);
|
|
443
|
+
}
|
|
444
|
+
else if (value instanceof forms.FormArray) {
|
|
445
|
+
_this.addFormArrayControls(value, result);
|
|
446
|
+
}
|
|
447
|
+
else if (value instanceof forms.FormControl) {
|
|
448
|
+
_this.addFormControl(value, result);
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
};
|
|
452
|
+
FormComponent.prototype.getAllFormControls = function () {
|
|
453
|
+
var result = [];
|
|
454
|
+
this.addFormGroupControls(this.formGroup, result);
|
|
455
|
+
return result;
|
|
456
|
+
};
|
|
457
|
+
FormComponent.prototype.addFormControl = function (control, result) {
|
|
458
|
+
result.push(control);
|
|
459
|
+
};
|
|
460
|
+
FormComponent.prototype.disableInactiveFormControl = function (control) {
|
|
461
|
+
if (!this.activeControls.some(function (e) { return e.formControl === control; })) {
|
|
462
|
+
control.disable();
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
FormComponent.prototype.trySubmit = function () {
|
|
466
|
+
var _this = this;
|
|
467
|
+
var _a, _b;
|
|
468
|
+
this.formGroup.markAllAsTouched();
|
|
469
|
+
var allControls = this.getAllFormControls();
|
|
470
|
+
var originalDisabledStates = allControls.map(function (e) {
|
|
471
|
+
return { control: e, disabled: e.disabled };
|
|
472
|
+
});
|
|
473
|
+
allControls.forEach(function (e) { return _this.disableInactiveFormControl(e); });
|
|
474
|
+
var values = this.formGroup.value;
|
|
475
|
+
if (this.formGroup.valid) {
|
|
476
|
+
this.setDisabledStatesForAllControls(originalDisabledStates);
|
|
477
|
+
return Promise.resolve(values);
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
(_b = (_a = this.activeControls.find(function (e) { return !e.formControl.valid; })) === null || _a === void 0 ? void 0 : _a.formElement) === null || _b === void 0 ? void 0 : _b.scrollTo();
|
|
481
|
+
this.setDisabledStatesForAllControls(originalDisabledStates);
|
|
482
|
+
return Promise.reject(invalidFieldsSymbol);
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
FormComponent.prototype.setDisabledStatesForAllControls = function (originalDisabledStates) {
|
|
486
|
+
originalDisabledStates.forEach(function (e) {
|
|
487
|
+
if (e.disabled) {
|
|
488
|
+
e.control.disable();
|
|
489
|
+
}
|
|
490
|
+
else {
|
|
491
|
+
e.control.enable();
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
};
|
|
495
|
+
return FormComponent;
|
|
496
|
+
}());
|
|
497
|
+
FormComponent.decorators = [
|
|
498
|
+
{ type: core.Component, args: [{
|
|
499
|
+
selector: 'klp-form',
|
|
500
|
+
template: "<form>\n\t<ng-content></ng-content>\n</form>\n\n\n",
|
|
501
|
+
styles: [":host{display:block}:host.row{display:flex}"]
|
|
502
|
+
},] }
|
|
503
|
+
];
|
|
504
|
+
FormComponent.ctorParameters = function () { return [
|
|
505
|
+
{ type: FormComponent, decorators: [{ type: core.SkipSelf }, { type: core.Optional }] },
|
|
506
|
+
{ type: SubFormDirective, decorators: [{ type: core.Optional }] }
|
|
507
|
+
]; };
|
|
508
|
+
FormComponent.propDecorators = {
|
|
509
|
+
formGroup: [{ type: core.Input }]
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
var FORM_ERROR_MESSAGES = new core.InjectionToken('form.error.messages');
|
|
513
|
+
var DEFAULT_ERROR_MESSAGES = {
|
|
514
|
+
min: "Use a number larger than %min%",
|
|
515
|
+
max: "Use a number smaller than %max%",
|
|
516
|
+
required: "This field is required",
|
|
517
|
+
email: "Use a valid email address",
|
|
518
|
+
minLength: "Has to be longer than %minLength% character(s)",
|
|
519
|
+
maxLength: "Has to be shorter than %maxLength% character(s)",
|
|
520
|
+
pattern: "This input is not valid",
|
|
521
|
+
matchPassword: "Passwords must match",
|
|
522
|
+
date: "Enter a valid date",
|
|
523
|
+
};
|
|
524
|
+
var FormElementComponent = /** @class */ (function () {
|
|
525
|
+
function FormElementComponent(parent, customMessages) {
|
|
526
|
+
this.parent = parent;
|
|
527
|
+
this.customMessages = customMessages;
|
|
528
|
+
this.direction = 'horizontal';
|
|
529
|
+
this.captionSpacing = 'percentages';
|
|
530
|
+
this.swapInputAndCaption = false;
|
|
531
|
+
this.errorMessages = DEFAULT_ERROR_MESSAGES;
|
|
532
|
+
this.customErrorHandlers = [];
|
|
533
|
+
}
|
|
534
|
+
FormElementComponent.prototype.substituteParameters = function (message, parameters) {
|
|
535
|
+
return Object.keys(parameters).reduce(function (msg, key) {
|
|
536
|
+
return msg.replace("%" + key + "%", parameters[key]);
|
|
537
|
+
}, message);
|
|
538
|
+
};
|
|
539
|
+
FormElementComponent.prototype.registerControl = function (formControl) {
|
|
540
|
+
// console.log('register');
|
|
541
|
+
// console.log(this.caption);
|
|
542
|
+
this.attachedControl = formControl;
|
|
543
|
+
this.parent.registerControl(formControl, this);
|
|
544
|
+
};
|
|
545
|
+
FormElementComponent.prototype.unregisterControl = function (formControl) {
|
|
546
|
+
this.attachedControl = null;
|
|
547
|
+
this.parent.unregisterControl(formControl);
|
|
548
|
+
};
|
|
549
|
+
FormElementComponent.prototype.getAttachedControl = function () {
|
|
550
|
+
return this.attachedControl;
|
|
551
|
+
};
|
|
552
|
+
FormElementComponent.prototype.registerErrorHandler = function (error, templateRef) {
|
|
553
|
+
this.customErrorHandlers.push({ error: error, templateRef: templateRef });
|
|
554
|
+
};
|
|
555
|
+
FormElementComponent.prototype.registerCaption = function (templateRef) {
|
|
556
|
+
this.captionRef = templateRef;
|
|
557
|
+
};
|
|
558
|
+
FormElementComponent.prototype.getErrorToShow = function () {
|
|
559
|
+
var _a, _b, _c;
|
|
560
|
+
if (((_a = this.attachedControl) === null || _a === void 0 ? void 0 : _a.touched) === true && ((_b = this.attachedControl) === null || _b === void 0 ? void 0 : _b.errors)) {
|
|
561
|
+
return Object.keys((_c = this.attachedControl) === null || _c === void 0 ? void 0 : _c.errors)[0];
|
|
562
|
+
}
|
|
563
|
+
return null;
|
|
564
|
+
};
|
|
565
|
+
FormElementComponent.prototype.getCustomErrorHandler = function (error) {
|
|
566
|
+
return this.customErrorHandlers.find(function (e) { return e.error === error; });
|
|
567
|
+
};
|
|
568
|
+
FormElementComponent.prototype.showDefaultError = function (error) {
|
|
569
|
+
return this.getErrorToShow() === error && !this.customErrorHandlers.some(function (e) { return e.error === error; });
|
|
570
|
+
};
|
|
571
|
+
FormElementComponent.prototype.getScrollableParent = function (node) {
|
|
572
|
+
if (node == null) {
|
|
573
|
+
return null;
|
|
574
|
+
}
|
|
575
|
+
if (node.scrollHeight > node.clientHeight) {
|
|
576
|
+
return node;
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
return this.getScrollableParent(node.parentNode);
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
FormElementComponent.prototype.scrollTo = function () {
|
|
583
|
+
var _a;
|
|
584
|
+
this.internalComponentRef.nativeElement.scrollIntoView(true);
|
|
585
|
+
// to give some breathing room, we scroll 100px more to the top
|
|
586
|
+
(_a = this.getScrollableParent(this.internalComponentRef.nativeElement)) === null || _a === void 0 ? void 0 : _a.scrollBy(0, -100);
|
|
587
|
+
};
|
|
588
|
+
FormElementComponent.prototype.getErrorMessages = function (key) {
|
|
589
|
+
var _a, _b, _c;
|
|
590
|
+
return (_c = (_b = (_a = this.customMessages) === null || _a === void 0 ? void 0 : _a[key]) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : this.errorMessages[key];
|
|
591
|
+
};
|
|
592
|
+
return FormElementComponent;
|
|
593
|
+
}());
|
|
594
|
+
FormElementComponent.decorators = [
|
|
595
|
+
{ type: core.Component, args: [{
|
|
596
|
+
selector: 'klp-form-element',
|
|
597
|
+
template: "<ng-template #errorRef>\n\t<div *ngIf=\"getErrorToShow()\" class=\"errorContainer\">\n\t\t<div *ngIf=\"showDefaultError('min')\">{{substituteParameters(getErrorMessages(\"min\"), {min: attachedControl.errors.min.min})}}</div>\n\t\t<div *ngIf=\"showDefaultError('max')\">{{substituteParameters(getErrorMessages(\"max\"), {max: attachedControl.errors.max.max})}}</div>\n\t\t<div *ngIf=\"showDefaultError('required')\">{{getErrorMessages(\"required\")}}</div>\n\t\t<div *ngIf=\"showDefaultError('email')\">{{getErrorMessages(\"email\")}}</div>\n\t\t<div *ngIf=\"showDefaultError('minlength')\">{{substituteParameters(getErrorMessages(\"minLength\"), {minLength: attachedControl.errors.minlength.requiredLength})}}</div>\n\t\t<div *ngIf=\"showDefaultError('maxlength')\">{{substituteParameters(getErrorMessages(\"maxLength\"), {maxLength: attachedControl.errors.maxlength.requiredLength})}}</div>\n\t\t<div *ngIf=\"showDefaultError('pattern')\">{{getErrorMessages(\"pattern\")}}</div>\n\t\t<div *ngIf=\"showDefaultError('MatchPassword')\">{{getErrorMessages(\"matchPassword\")}}</div>\n\t\t<div *ngIf=\"showDefaultError('date')\">{{getErrorMessages(\"date\")}}</div>\n\t\t<div *ngIf=\"showDefaultError('message')\">{{attachedControl.errors.message.value}}</div>\n\t\t<div [ngTemplateOutlet]=\"getCustomErrorHandler(getErrorToShow())?.templateRef\"></div>\n\t</div>\n</ng-template>\n<ng-container *ngIf=\"direction === 'horizontal'\" [ngTemplateOutlet]=\"errorRef\"></ng-container>\n<div *ngIf=\"attachedControl\" class=\"componentContainer\" [ngClass]=\"{vertical: direction === 'vertical', reverseOrder: swapInputAndCaption}\" #internalComponentRef>\n\t<div class=\"caption\" [ngClass]=\"{ hasErrors: getErrorToShow() && attachedControl.touched, percentageSpacing: captionSpacing === 'percentages' }\">\n\t\t<div *ngIf=\"captionRef\" [ngTemplateOutlet]=\"captionRef\"></div>\n\t\t<div *ngIf=\"!captionRef\">{{caption}}</div>\n\t</div>\n\t<ng-container *ngIf=\"direction === 'vertical'\" [ngTemplateOutlet]=\"errorRef\"></ng-container>\n\t<div class=\"inputContainer\" [ngClass]=\"{ percentageSpacing: captionSpacing === 'percentages' }\">\n\t\t<ng-content></ng-content>\n\t</div>\n</div>\n",
|
|
598
|
+
styles: [":host{display:block;margin-top:1.25rem}.componentContainer{align-items:center;display:flex}.componentContainer.reverseOrder{flex-direction:row-reverse;justify-content:flex-end}.componentContainer.vertical{display:block;margin-bottom:1rem}.componentContainer.vertical .inputContainer{margin-top:.3125rem}.componentContainer.vertical .errorContainer{margin-left:0}.caption{color:#515365;flex:0 0 auto;font-weight:700}.caption.percentageSpacing{flex:0 0 40%}.caption.hasErrors{color:#ff8000}.inputContainer{flex:0 0 auto}.inputContainer.percentageSpacing{flex:0 0 60%}.errorContainer{color:#ff8000;margin-left:40%}"]
|
|
599
|
+
},] }
|
|
600
|
+
];
|
|
601
|
+
FormElementComponent.ctorParameters = function () { return [
|
|
602
|
+
{ type: FormComponent, decorators: [{ type: core.Host }, { type: core.Optional }] },
|
|
603
|
+
{ type: undefined, decorators: [{ type: core.Inject, args: [FORM_ERROR_MESSAGES,] }, { type: core.Optional }] }
|
|
604
|
+
]; };
|
|
605
|
+
FormElementComponent.propDecorators = {
|
|
606
|
+
caption: [{ type: core.Input }],
|
|
607
|
+
direction: [{ type: core.Input }],
|
|
608
|
+
captionSpacing: [{ type: core.Input }],
|
|
609
|
+
swapInputAndCaption: [{ type: core.Input }],
|
|
610
|
+
internalComponentRef: [{ type: core.ViewChild, args: ['internalComponentRef',] }]
|
|
611
|
+
};
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* This component is a base in order to create a component that supports ngModel.
|
|
615
|
+
* Some important things to know about it:
|
|
616
|
+
*
|
|
617
|
+
* innerValue = your own inner state, which you should use to store the current state of what ngModel should be.
|
|
618
|
+
* writeValue() = called by angular, when ngModel is changed from OUTSIDE of the component. Feel free to patch this method if you need inner logic to happen when ngModel is altered from the outside. Always remember to also call the super.writeValue if you do!
|
|
619
|
+
* setInnerValueAndNotify() = call this when you want your ngModel to be updated from INSIDE of your component, and provide it to the OUTSIDE.
|
|
620
|
+
* ngOnInit() = Used to support the angular reactive forms framework. If you use ngOnInit in your own component (which happens fairly often) you must not forget to call the super.ngOnInit() method.
|
|
621
|
+
*/
|
|
622
|
+
var ValueAccessorBase = /** @class */ (function () {
|
|
623
|
+
function ValueAccessorBase(parent, controlContainer) {
|
|
624
|
+
this.parent = parent;
|
|
625
|
+
this.controlContainer = controlContainer;
|
|
626
|
+
this.changed = new Array();
|
|
627
|
+
this.touched = new Array();
|
|
628
|
+
this.disabled = false;
|
|
629
|
+
// we support both providing just the formControlName and the full formControl
|
|
630
|
+
this.formControlName = null;
|
|
631
|
+
this.formControl = null;
|
|
632
|
+
}
|
|
633
|
+
ValueAccessorBase.prototype.ngOnInit = function () {
|
|
634
|
+
var _this = this;
|
|
635
|
+
var _a, _b, _c;
|
|
636
|
+
if (this.formControl) {
|
|
637
|
+
this.attachedFormControl = this.formControl;
|
|
638
|
+
}
|
|
639
|
+
else if (stringIsSetAndNotEmpty(this.formControlName)) {
|
|
640
|
+
this.attachedFormControl = (_a = this.controlContainer) === null || _a === void 0 ? void 0 : _a.control.get(this.formControlName);
|
|
641
|
+
if (isNullOrUndefined(this.attachedFormControl)) {
|
|
642
|
+
throw new Error("Form element '" + this.formControlName + "' with caption '" + ((_b = this.parent) === null || _b === void 0 ? void 0 : _b.caption) + "' is not declared in your FormGroup.");
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
if (this.attachedFormControl) {
|
|
646
|
+
this.disabled = this.attachedFormControl.disabled;
|
|
647
|
+
this.attachedFormControl.statusChanges.subscribe(function () {
|
|
648
|
+
_this.disabled = _this.attachedFormControl.disabled;
|
|
649
|
+
});
|
|
650
|
+
(_c = this.parent) === null || _c === void 0 ? void 0 : _c.registerControl(this.attachedFormControl);
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
ValueAccessorBase.prototype.isInErrorState = function () {
|
|
654
|
+
return this.attachedFormControl && this.attachedFormControl.status === 'INVALID' && this.attachedFormControl.touched;
|
|
655
|
+
};
|
|
656
|
+
ValueAccessorBase.prototype.ngOnDestroy = function () {
|
|
657
|
+
var _a;
|
|
658
|
+
if (this.attachedFormControl) {
|
|
659
|
+
(_a = this.parent) === null || _a === void 0 ? void 0 : _a.unregisterControl(this.attachedFormControl);
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
ValueAccessorBase.prototype.touch = function () {
|
|
663
|
+
this.touched.forEach(function (f) { return f(); });
|
|
664
|
+
};
|
|
665
|
+
ValueAccessorBase.prototype.writeValue = function (value) {
|
|
666
|
+
this.innerValue = value;
|
|
667
|
+
};
|
|
668
|
+
ValueAccessorBase.prototype.registerOnChange = function (fn) {
|
|
669
|
+
this.changed.push(fn);
|
|
670
|
+
};
|
|
671
|
+
ValueAccessorBase.prototype.registerOnTouched = function (fn) {
|
|
672
|
+
this.touched.push(fn);
|
|
673
|
+
};
|
|
674
|
+
ValueAccessorBase.prototype.setInnerValueAndNotify = function (value) {
|
|
675
|
+
this.innerValue = value;
|
|
676
|
+
this.changed.forEach(function (fn) { return fn(value); });
|
|
677
|
+
};
|
|
678
|
+
ValueAccessorBase.prototype.resetToNull = function () {
|
|
679
|
+
this.setInnerValueAndNotify(null);
|
|
680
|
+
};
|
|
681
|
+
return ValueAccessorBase;
|
|
682
|
+
}());
|
|
683
|
+
ValueAccessorBase.decorators = [
|
|
684
|
+
{ type: core.Component, args: [{
|
|
685
|
+
selector: '',
|
|
686
|
+
template: ''
|
|
687
|
+
},] }
|
|
688
|
+
];
|
|
689
|
+
ValueAccessorBase.ctorParameters = function () { return [
|
|
690
|
+
{ type: FormElementComponent, decorators: [{ type: core.Host }, { type: core.Optional }] },
|
|
691
|
+
{ type: forms.ControlContainer, decorators: [{ type: core.Host }, { type: core.Optional }] }
|
|
692
|
+
]; };
|
|
693
|
+
ValueAccessorBase.propDecorators = {
|
|
694
|
+
disabled: [{ type: core.Input }],
|
|
695
|
+
formControlName: [{ type: core.Input }],
|
|
696
|
+
formControl: [{ type: core.Input }]
|
|
697
|
+
};
|
|
698
|
+
|
|
699
|
+
var ButtonComponent = /** @class */ (function () {
|
|
700
|
+
function ButtonComponent() {
|
|
701
|
+
this.variant = 'white';
|
|
702
|
+
this.size = 'medium';
|
|
703
|
+
this.fullWidth = false;
|
|
704
|
+
this.hasBorder = true;
|
|
705
|
+
this.disabled = false;
|
|
706
|
+
this.isLoading = false;
|
|
707
|
+
this.type = 'button';
|
|
708
|
+
}
|
|
709
|
+
Object.defineProperty(ButtonComponent.prototype, "_", {
|
|
710
|
+
get: function () {
|
|
711
|
+
return this.fullWidth;
|
|
712
|
+
},
|
|
713
|
+
enumerable: false,
|
|
714
|
+
configurable: true
|
|
715
|
+
});
|
|
716
|
+
ButtonComponent.prototype.onClick = function (event) {
|
|
717
|
+
if (this.disabled) {
|
|
718
|
+
event.stopPropagation();
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
return ButtonComponent;
|
|
722
|
+
}());
|
|
723
|
+
ButtonComponent.decorators = [
|
|
724
|
+
{ type: core.Component, args: [{
|
|
725
|
+
selector: 'klp-form-button',
|
|
726
|
+
template: "<button class=\"buttonFundamentals\"\n\t[ngClass]=\"[\n\t\tvariant,\n\t\tsize,\n\t\tfullWidth ? 'fullWidth' : '',\n\t\thasBorder ? '' : 'no-border',\n\t\tdisabled ? 'disabled' : ''\n\t]\"\n\t[type]=\"type\"\n\t(click)=\"onClick($event)\"\n>\n\t<div class=\"caption\" [ngClass]=\"{invisible: isLoading}\">\n\t\t<ng-content></ng-content>\n\t</div>\n\t<div class=\"loadingSpinnerContainer\" *ngIf=\"isLoading\">\n\t\t<klp-form-loading-indicator variant=\"spinner\" size=\"small\"></klp-form-loading-indicator>\n\t</div>\n</button>\n",
|
|
727
|
+
styles: [":host{display:inline-block}:host._fullWidth{display:block}.buttonFundamentals{border:1px solid #e6ecf5;border-radius:5px;color:#888da8;cursor:pointer;font-size:13px;font-weight:700;letter-spacing:1px;padding:10px 20px}.fullWidth{width:100%}.no-border{border:none}.caption.invisible{visibility:hidden}button{position:relative}.loadingSpinnerContainer{align-items:center;bottom:0;display:flex;justify-content:center;left:0;position:absolute;right:0;top:0}.small{padding-bottom:.375rem;padding-top:.375rem}.large{line-height:2}.white{background-color:#fff;border-color:#d4deee;color:#515365;font-weight:500}.white:active,.white:hover{background-color:#edf2f8;border-color:#edf2f8;color:#515365}.white:focus{text-decoration:underline}.greenFilled{background-color:#27bb5f;border-color:#27bb5f;color:#fff}.greenFilled:hover{background-color:#2bd06a;border-color:#2bd06a;color:#fff}.greenFilled:focus{text-decoration:underline}.greenFilled:active{background-color:#23a654;border-color:#23a654}.greenOutlined{background-color:#fff;border-color:#27bb5f;color:#27bb5f}.greenOutlined:hover{background-color:#2bd06a;border-color:#2bd06a;color:#fff}.greenOutlined:focus{text-decoration:underline}.greenOutlined:active{background-color:#23a654;border-color:#23a654}.greenLink{background:none;border:none;color:#27bb5f;padding:0}.greenLink:focus,.greenLink:hover{text-decoration:underline}.contextMenuItem{background-color:#fff;border-color:#fff;color:#888da8}.contextMenuItem:hover{background-color:#f6f7fb;border-color:#f6f7fb}.contextMenuItem:active,.contextMenuItem:focus{text-decoration:underline}.redFilled{background-color:#ff3c7e;border-color:#ff3c7e;color:#fff}.redFilled:hover{background-color:#ff568f;border-color:#ff568f;color:#fff}.redFilled:focus{text-decoration:underline}.redFilled:active{background-color:#ff236d;border-color:#ff236d}.redOutlined{background-color:#fff;border-color:#ff3c7e;color:#ff3c7e}.redOutlined:hover{background-color:#ff568f;border-color:#ff568f;color:#fff}.redOutlined:focus{text-decoration:underline}.redOutlined:active{background-color:#ff236d;border-color:#ff236d}.orangeFilled{background-color:#ff8000;border-color:#ff8000;color:#fff}.orangeFilled:hover{background-color:#ff8d1a;border-color:#ff8d1a;color:#fff}.orangeFilled:focus{text-decoration:underline}.orangeFilled:active{background-color:#e67300;border-color:#e67300}"]
|
|
728
|
+
},] }
|
|
729
|
+
];
|
|
730
|
+
ButtonComponent.propDecorators = {
|
|
731
|
+
variant: [{ type: core.Input }],
|
|
732
|
+
size: [{ type: core.Input }],
|
|
733
|
+
fullWidth: [{ type: core.Input }],
|
|
734
|
+
hasBorder: [{ type: core.Input }],
|
|
735
|
+
disabled: [{ type: core.Input }],
|
|
736
|
+
isLoading: [{ type: core.Input }],
|
|
737
|
+
type: [{ type: core.Input }],
|
|
738
|
+
_: [{ type: core.HostBinding, args: ['class._fullWidth',] }]
|
|
739
|
+
};
|
|
740
|
+
|
|
675
741
|
var CheckboxComponent = /** @class */ (function (_super) {
|
|
676
742
|
__extends(CheckboxComponent, _super);
|
|
677
743
|
function CheckboxComponent() {
|
|
@@ -1157,6 +1223,7 @@
|
|
|
1157
1223
|
FormErrorComponent,
|
|
1158
1224
|
FormSubmitButtonComponent,
|
|
1159
1225
|
FormComponent,
|
|
1226
|
+
SubFormDirective,
|
|
1160
1227
|
],
|
|
1161
1228
|
exports: [
|
|
1162
1229
|
ValueAccessorBase,
|
|
@@ -1176,6 +1243,7 @@
|
|
|
1176
1243
|
FormErrorComponent,
|
|
1177
1244
|
FormSubmitButtonComponent,
|
|
1178
1245
|
FormComponent,
|
|
1246
|
+
SubFormDirective,
|
|
1179
1247
|
]
|
|
1180
1248
|
},] }
|
|
1181
1249
|
];
|
|
@@ -1206,6 +1274,8 @@
|
|
|
1206
1274
|
exports.PasswordFieldComponent = PasswordFieldComponent;
|
|
1207
1275
|
exports.SelectComponent = SelectComponent;
|
|
1208
1276
|
exports.SortableItemsComponent = SortableItemsComponent;
|
|
1277
|
+
exports.SubForm = SubForm;
|
|
1278
|
+
exports.SubFormDirective = SubFormDirective;
|
|
1209
1279
|
exports.TextInputComponent = TextInputComponent;
|
|
1210
1280
|
exports.ToggleComponent = ToggleComponent;
|
|
1211
1281
|
exports.ValueAccessorBase = ValueAccessorBase;
|