@klippa/ngx-enhancy-forms 18.23.8 → 18.24.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/esm2022/lib/form/form.component.mjs +46 -35
- package/esm2022/lib/withTooltip.component.mjs +7 -2
- package/fesm2022/klippa-ngx-enhancy-forms.mjs +52 -36
- package/fesm2022/klippa-ngx-enhancy-forms.mjs.map +1 -1
- package/lib/form/form.component.d.ts +5 -3
- package/lib/withTooltip.component.d.ts +2 -1
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ import { Directive, Input, EventEmitter, Component, SkipSelf, Optional, Output,
|
|
|
3
3
|
import * as i1 from '@angular/common';
|
|
4
4
|
import { CommonModule } from '@angular/common';
|
|
5
5
|
import * as i2 from '@angular/forms';
|
|
6
|
-
import { UntypedFormArray, UntypedFormGroup, FormControl, UntypedFormControl,
|
|
6
|
+
import { UntypedFormArray, UntypedFormGroup, FormControl, UntypedFormControl, FormGroup, FormArray, NG_VALUE_ACCESSOR, FormsModule } from '@angular/forms';
|
|
7
7
|
import { isString } from 'lodash-es';
|
|
8
8
|
import { isArray } from 'lodash';
|
|
9
9
|
import * as i4 from '@ng-select/ng-select';
|
|
@@ -173,6 +173,7 @@ class FormComponent {
|
|
|
173
173
|
this.activeControls = [];
|
|
174
174
|
}
|
|
175
175
|
ngOnInit() {
|
|
176
|
+
this.topLevelFormControl = this.formGroup ?? this.formArray;
|
|
176
177
|
if (isValueSet(this.patchValueInterceptor)) {
|
|
177
178
|
this.addSupportForPatchValueInterceptor();
|
|
178
179
|
}
|
|
@@ -184,13 +185,13 @@ class FormComponent {
|
|
|
184
185
|
throw new Error(`cannot index FormArray with ${typeof injectAt}`);
|
|
185
186
|
}
|
|
186
187
|
if (injectInto.at(injectAt)?.disabled) {
|
|
187
|
-
this.
|
|
188
|
+
this.topLevelFormControl.disable();
|
|
188
189
|
}
|
|
189
190
|
const valueBeforeInject = injectInto.at(injectAt)?.value;
|
|
190
191
|
if (isValueSet(valueBeforeInject)) {
|
|
191
|
-
this.
|
|
192
|
+
this.topLevelFormControl.patchValue(valueBeforeInject);
|
|
192
193
|
}
|
|
193
|
-
injectInto.setControl(injectAt, this.
|
|
194
|
+
injectInto.setControl(injectAt, this.topLevelFormControl);
|
|
194
195
|
this.onInjected.emit(valueBeforeInject);
|
|
195
196
|
}
|
|
196
197
|
else if (injectInto instanceof UntypedFormGroup) {
|
|
@@ -198,13 +199,13 @@ class FormComponent {
|
|
|
198
199
|
throw new Error(`cannot index FormGroup with ${typeof injectAt}`);
|
|
199
200
|
}
|
|
200
201
|
if (injectInto.get(injectAt)?.disabled) {
|
|
201
|
-
this.
|
|
202
|
+
this.topLevelFormControl.disable();
|
|
202
203
|
}
|
|
203
204
|
const valueBeforeInject = injectInto.get(injectAt)?.value;
|
|
204
205
|
if (isValueSet(valueBeforeInject)) {
|
|
205
|
-
this.
|
|
206
|
+
this.topLevelFormControl.patchValue(valueBeforeInject);
|
|
206
207
|
}
|
|
207
|
-
injectInto.setControl(injectAt, this.
|
|
208
|
+
injectInto.setControl(injectAt, this.topLevelFormControl);
|
|
208
209
|
this.onInjected.emit(valueBeforeInject);
|
|
209
210
|
}
|
|
210
211
|
}
|
|
@@ -225,7 +226,7 @@ class FormComponent {
|
|
|
225
226
|
const injectInto = this.subFormPlaceholder.injectInto;
|
|
226
227
|
const injectAt = this.subFormPlaceholder.at;
|
|
227
228
|
if (injectInto instanceof UntypedFormArray) {
|
|
228
|
-
const idx = injectInto.controls.findIndex(e => e === this.
|
|
229
|
+
const idx = injectInto.controls.findIndex(e => e === this.topLevelFormControl);
|
|
229
230
|
injectInto.setControl(idx, new FormControl());
|
|
230
231
|
}
|
|
231
232
|
else if (injectInto instanceof UntypedFormGroup) {
|
|
@@ -275,15 +276,15 @@ class FormComponent {
|
|
|
275
276
|
};
|
|
276
277
|
}
|
|
277
278
|
addSupportForPatchValueInterceptor() {
|
|
278
|
-
const fn = this.
|
|
279
|
+
const fn = this.topLevelFormControl.patchValue;
|
|
279
280
|
const newFn = (value, options) => {
|
|
280
281
|
this.patchValueInterceptor(value).then((val) => {
|
|
281
282
|
setTimeout(() => {
|
|
282
|
-
fn.call(this.
|
|
283
|
+
fn.call(this.topLevelFormControl, val, options);
|
|
283
284
|
});
|
|
284
285
|
});
|
|
285
286
|
};
|
|
286
|
-
this.
|
|
287
|
+
this.topLevelFormControl.patchValue = newFn;
|
|
287
288
|
}
|
|
288
289
|
registerControl(formControl, formElement) {
|
|
289
290
|
this.activeControls.push({ formControl, formElement });
|
|
@@ -334,7 +335,12 @@ class FormComponent {
|
|
|
334
335
|
}
|
|
335
336
|
getAllFormControls() {
|
|
336
337
|
const result = [];
|
|
337
|
-
|
|
338
|
+
if (this.topLevelFormControl instanceof FormGroup) {
|
|
339
|
+
this.addFormGroupControls(this.topLevelFormControl, result);
|
|
340
|
+
}
|
|
341
|
+
else if (this.topLevelFormControl instanceof FormArray) {
|
|
342
|
+
this.addFormArrayControls(this.topLevelFormControl, result);
|
|
343
|
+
}
|
|
338
344
|
return result;
|
|
339
345
|
}
|
|
340
346
|
addFormControl(control, result) {
|
|
@@ -352,36 +358,39 @@ class FormComponent {
|
|
|
352
358
|
return this.warnings.get(control);
|
|
353
359
|
}
|
|
354
360
|
trySubmit() {
|
|
355
|
-
this.
|
|
361
|
+
this.topLevelFormControl.markAllAsTouched();
|
|
356
362
|
const allControls = this.getAllFormControls();
|
|
357
363
|
const originalDisabledStates = allControls.map(e => {
|
|
358
364
|
return { control: e, disabled: e.disabled };
|
|
359
365
|
});
|
|
360
366
|
allControls.forEach(e => this.disableInactiveFormControl(e));
|
|
361
367
|
allControls.forEach(e => e.updateValueAndValidity());
|
|
362
|
-
const formGroupValue = this.
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
.
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
.
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
368
|
+
const formGroupValue = this.topLevelFormControl.value;
|
|
369
|
+
if (this.topLevelFormControl instanceof FormGroup) {
|
|
370
|
+
const renderedAndEnabledValues = this.getRenderedFieldValuesFormGroup(this.topLevelFormControl, true);
|
|
371
|
+
const renderedButDisabledValues = this.getRenderedFieldValuesFormGroup(this.topLevelFormControl, false);
|
|
372
|
+
return new Promise((resolve, reject) => {
|
|
373
|
+
if (this.topLevelFormControl.pending) {
|
|
374
|
+
const sub = this.topLevelFormControl.statusChanges.subscribe((res) => {
|
|
375
|
+
if (res !== 'PENDING') {
|
|
376
|
+
sub.unsubscribe();
|
|
377
|
+
this.handleSubmission(originalDisabledStates, renderedAndEnabledValues, renderedButDisabledValues, formGroupValue)
|
|
378
|
+
.then(resolve)
|
|
379
|
+
.catch(reject);
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
this.handleSubmission(originalDisabledStates, renderedAndEnabledValues, renderedButDisabledValues, formGroupValue)
|
|
385
|
+
.then(resolve)
|
|
386
|
+
.catch(reject);
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
throw new Error('Submitting a FormArray as topLevel not supported (yet). Wrap it in a FormGroup.');
|
|
382
391
|
}
|
|
383
392
|
handleSubmission(originalDisabledStates, renderedAndEnabledValues, renderedButDisabledValues, formGroupValue) {
|
|
384
|
-
if (this.
|
|
393
|
+
if (this.topLevelFormControl.invalid) {
|
|
385
394
|
this.activeControls.find((e) => e.formControl.invalid)?.formElement?.scrollTo();
|
|
386
395
|
this.setDisabledStatesForAllControls(originalDisabledStates);
|
|
387
396
|
return Promise.reject(invalidFieldsSymbol);
|
|
@@ -436,7 +445,7 @@ class FormComponent {
|
|
|
436
445
|
});
|
|
437
446
|
}
|
|
438
447
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.0", ngImport: i0, type: FormComponent, deps: [{ token: FormComponent, optional: true, skipSelf: true }, { token: SubFormDirective, optional: true }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
439
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.0", type: FormComponent, selector: "klp-form", inputs: { readOnly: "readOnly", showErrorMessages: "showErrorMessages", errorMessageLocation: "errorMessageLocation", formGroup: "formGroup", warnings: "warnings", errors: "errors", patchValueInterceptor: "patchValueInterceptor", allowSubmitOn: "allowSubmitOn" }, outputs: { onInjected: "onInjected" }, usesOnChanges: true, ngImport: i0, template: "<form>\n\t<ng-content></ng-content>\n</form>\n\n\n", styles: [":host{display:block}:host.row{display:flex}:host form{height:inherit}\n"], dependencies: [{ kind: "directive", type: i2.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i2.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i2.NgForm, selector: "form:not([ngNoForm]):not([formGroup]),ng-form,[ngForm]", inputs: ["ngFormOptions"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }] }); }
|
|
448
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.0", type: FormComponent, selector: "klp-form", inputs: { readOnly: "readOnly", showErrorMessages: "showErrorMessages", errorMessageLocation: "errorMessageLocation", formGroup: "formGroup", formArray: "formArray", warnings: "warnings", errors: "errors", patchValueInterceptor: "patchValueInterceptor", allowSubmitOn: "allowSubmitOn" }, outputs: { onInjected: "onInjected" }, usesOnChanges: true, ngImport: i0, template: "<form>\n\t<ng-content></ng-content>\n</form>\n\n\n", styles: [":host{display:block}:host.row{display:flex}:host form{height:inherit}\n"], dependencies: [{ kind: "directive", type: i2.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i2.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i2.NgForm, selector: "form:not([ngNoForm]):not([formGroup]),ng-form,[ngForm]", inputs: ["ngFormOptions"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }] }); }
|
|
440
449
|
}
|
|
441
450
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.0", ngImport: i0, type: FormComponent, decorators: [{
|
|
442
451
|
type: Component,
|
|
@@ -455,6 +464,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.0", ngImpor
|
|
|
455
464
|
type: Input
|
|
456
465
|
}], formGroup: [{
|
|
457
466
|
type: Input
|
|
467
|
+
}], formArray: [{
|
|
468
|
+
type: Input
|
|
458
469
|
}], warnings: [{
|
|
459
470
|
type: Input
|
|
460
471
|
}], errors: [{
|
|
@@ -2578,6 +2589,9 @@ class WithTooltipDirective {
|
|
|
2578
2589
|
this.div.style.top = `${el.nativeElement.getBoundingClientRect().y + el.nativeElement.getBoundingClientRect().height}px`;
|
|
2579
2590
|
this.div.style.transform = `translate(calc(-100% + ${el.nativeElement.getBoundingClientRect().width}px), calc(0% + 0.3rem))`;
|
|
2580
2591
|
}
|
|
2592
|
+
if (this.tooltipMinWidth > 0) {
|
|
2593
|
+
this.div.style.minWidth = `${this.tooltipMinWidth}px`;
|
|
2594
|
+
}
|
|
2581
2595
|
this.div.style.maxWidth = `${this.tooltipMaxWidth}px`;
|
|
2582
2596
|
this.div.style.whiteSpace = 'break-spaces';
|
|
2583
2597
|
this.div.style.border = `1px solid ${colors[this.klpWithTooltip].withAlpha}`;
|
|
@@ -2676,7 +2690,7 @@ class WithTooltipDirective {
|
|
|
2676
2690
|
this.viewRefForTemplate.destroy();
|
|
2677
2691
|
}
|
|
2678
2692
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.0", ngImport: i0, type: WithTooltipDirective, deps: [{ token: i0.ElementRef }, { token: i0.ApplicationRef }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
2679
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.0", type: WithTooltipDirective, selector: "[klpWithTooltip]", inputs: { klpWithTooltip: "klpWithTooltip", tooltipText: "tooltipText", tooltipTemplate: "tooltipTemplate", tooltipMaxWidth: "tooltipMaxWidth", position: "position" }, ngImport: i0 }); }
|
|
2693
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.0", type: WithTooltipDirective, selector: "[klpWithTooltip]", inputs: { klpWithTooltip: "klpWithTooltip", tooltipText: "tooltipText", tooltipTemplate: "tooltipTemplate", tooltipMinWidth: "tooltipMinWidth", tooltipMaxWidth: "tooltipMaxWidth", position: "position" }, ngImport: i0 }); }
|
|
2680
2694
|
}
|
|
2681
2695
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.0", ngImport: i0, type: WithTooltipDirective, decorators: [{
|
|
2682
2696
|
type: Directive,
|
|
@@ -2689,6 +2703,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.0", ngImpor
|
|
|
2689
2703
|
type: Input
|
|
2690
2704
|
}], tooltipTemplate: [{
|
|
2691
2705
|
type: Input
|
|
2706
|
+
}], tooltipMinWidth: [{
|
|
2707
|
+
type: Input
|
|
2692
2708
|
}], tooltipMaxWidth: [{
|
|
2693
2709
|
type: Input
|
|
2694
2710
|
}], position: [{
|