@tft/crispr-forms 13.0.10 → 13.0.13
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/esm2020/lib/field-component-map.const.mjs +5 -2
- package/esm2020/lib/field.directive.mjs +16 -6
- package/esm2020/lib/form/form.component.mjs +4 -6
- package/esm2020/lib/form.helpers.mjs +6 -2
- package/fesm2015/tft-crispr-forms.mjs +26 -11
- package/fesm2015/tft-crispr-forms.mjs.map +1 -1
- package/fesm2020/tft-crispr-forms.mjs +26 -11
- package/fesm2020/tft-crispr-forms.mjs.map +1 -1
- package/lib/field-component-map.const.d.ts +4 -2
- package/lib/field.directive.d.ts +7 -2
- package/lib/form/form.component.d.ts +3 -3
- package/package.json +1 -1
- package/tft-crispr-forms-13.0.13.tgz +0 -0
- package/tft-crispr-forms-13.0.10.tgz +0 -0
|
@@ -242,10 +242,14 @@ function buildFormGroupFromConfig(config, value = null, group = new FormGroup({}
|
|
|
242
242
|
if (isControlConfig(controlConfig)) {
|
|
243
243
|
// then add a control to the group using the controlName from configuration
|
|
244
244
|
const { controlName } = controlConfig;
|
|
245
|
+
if (group.get(controlName)) {
|
|
246
|
+
group.removeControl(controlName);
|
|
247
|
+
}
|
|
245
248
|
// if there's a value object and it has a non-null/undefined value for this field use it.
|
|
246
249
|
// Otherwise, default to null
|
|
247
250
|
const controlValue = (value && value[controlName]) ?? null;
|
|
248
|
-
|
|
251
|
+
const control = createControlForType(controlConfig, controlValue);
|
|
252
|
+
group.addControl(controlName, control);
|
|
249
253
|
}
|
|
250
254
|
});
|
|
251
255
|
group.setValidators(config.validators);
|
|
@@ -1561,7 +1565,10 @@ const FIELD_COMPONENTS = {
|
|
|
1561
1565
|
unitConversion: Promise.resolve().then(function () { return index$2; }).then(({ UnitConversionFieldComponent }) => UnitConversionFieldComponent)
|
|
1562
1566
|
};
|
|
1563
1567
|
function isControlComponent(component) {
|
|
1564
|
-
return isControlConfig(component.config) || component.config.controlType === ControlType.BUTTON;
|
|
1568
|
+
return isControlConfig(component.config) && 'value' in component; // || component.config.controlType === ControlType.BUTTON;
|
|
1569
|
+
}
|
|
1570
|
+
function isControlOrButtonComponent(component) {
|
|
1571
|
+
return isControlComponent(component) || component.config.controlType === ControlType.BUTTON;
|
|
1565
1572
|
}
|
|
1566
1573
|
|
|
1567
1574
|
class CrisprFieldDirective {
|
|
@@ -1570,6 +1577,16 @@ class CrisprFieldDirective {
|
|
|
1570
1577
|
this.renderer = renderer;
|
|
1571
1578
|
this.cdr = cdr;
|
|
1572
1579
|
}
|
|
1580
|
+
set value(value) {
|
|
1581
|
+
this._value = value;
|
|
1582
|
+
if (this.component && isControlComponent(this.component)) {
|
|
1583
|
+
this.component.value = value;
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
;
|
|
1587
|
+
get value() {
|
|
1588
|
+
return this._value;
|
|
1589
|
+
}
|
|
1573
1590
|
async ngOnInit() {
|
|
1574
1591
|
/**
|
|
1575
1592
|
* create component and set values from config on its instance
|
|
@@ -1578,11 +1595,11 @@ class CrisprFieldDirective {
|
|
|
1578
1595
|
const componentRef = this.container.createComponent(component);
|
|
1579
1596
|
this.component = componentRef.instance;
|
|
1580
1597
|
this.component.config = this.config;
|
|
1581
|
-
if (
|
|
1598
|
+
if (isControlOrButtonComponent(this.component)) {
|
|
1582
1599
|
this.component.group = this.group;
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1600
|
+
}
|
|
1601
|
+
if (isControlComponent(this.component)) {
|
|
1602
|
+
this.component.value = this.value;
|
|
1586
1603
|
}
|
|
1587
1604
|
this.cdr.detectChanges();
|
|
1588
1605
|
// adds any config classes to the dynamically generated component
|
|
@@ -1663,11 +1680,9 @@ class CrisprFormComponent {
|
|
|
1663
1680
|
this.statusChanges = this.form.statusChanges;
|
|
1664
1681
|
this.subs = [];
|
|
1665
1682
|
}
|
|
1666
|
-
|
|
1683
|
+
ngOnInit() {
|
|
1667
1684
|
// build out the form, note that we pass in the form as the third argument and the function modifies it
|
|
1668
|
-
|
|
1669
|
-
buildFormGroupFromConfig(this.config, this.value, this.form);
|
|
1670
|
-
}
|
|
1685
|
+
buildFormGroupFromConfig(this.config, this.value, this.form);
|
|
1671
1686
|
}
|
|
1672
1687
|
handleSubmit() {
|
|
1673
1688
|
this.form.markAllAsTouched();
|
|
@@ -1678,7 +1693,7 @@ class CrisprFormComponent {
|
|
|
1678
1693
|
}
|
|
1679
1694
|
}
|
|
1680
1695
|
CrisprFormComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.1", ngImport: i0, type: CrisprFormComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1681
|
-
CrisprFormComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.1", type: CrisprFormComponent, selector: "crispr-form", inputs: { config: "config", form: "form", value: "value" }, outputs: { submitted: "submitted", valueChanges: "valueChanges", statusChanges: "statusChanges" }, viewQueries: [{ propertyName: "submitTrigger", first: true, predicate: ["submitTrigger"], descendants: true }],
|
|
1696
|
+
CrisprFormComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.1", type: CrisprFormComponent, selector: "crispr-form", inputs: { config: "config", form: "form", value: "value" }, outputs: { submitted: "submitted", valueChanges: "valueChanges", statusChanges: "statusChanges" }, viewQueries: [{ propertyName: "submitTrigger", first: true, predicate: ["submitTrigger"], descendants: true }], ngImport: i0, template: "<form\n class=\"crispr-form\"\n [ngClass]=\"config.classes\"\n [formGroup]=\"form\"\n (ngSubmit)=\"handleSubmit()\"\n [autocomplete]=\"config.autocomplete || 'off'\"\n [errorDictionary]=\"config.errorDictionary\"\n #ngFormElement=\"ngForm\">\n\n <ng-container\n *ngFor=\"let field of config.fields;\"\n crisprField\n [value]=\"value | initialControlValue : field\"\n [config]=\"field\"\n [group]=\"form\">\n </ng-container>\n <!-- Hidden button, programmatically clicked when crispr form triggerSubmit function called.\n Uses a hidden button with type=\"submit\" because it will trigger both native form submit event\n (which the error handler has to listen for) and ngSubmit event -->\n <button #submitTrigger class=\"submit-trigger\" type=\"submit\">\n </button>\n</form>\n", styles: [".submit-trigger{display:none}\n"], directives: [{ type: i4$1.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { type: i4$1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { type: i5.ControlErrorsFormDirective, selector: "form", inputs: ["errorDictionary"] }, { type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i4$1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { type: i5.ControlErrorContainerDirective, selector: "[controlErrorContainer], [formGroup]" }, { type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: CrisprFieldDirective, selector: "[crisprField]", inputs: ["config", "group", "value"] }], pipes: { "initialControlValue": InitialControlValuePipe }, changeDetection: i0.ChangeDetectionStrategy.OnPush, preserveWhitespaces: true });
|
|
1682
1697
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.1", ngImport: i0, type: CrisprFormComponent, decorators: [{
|
|
1683
1698
|
type: Component,
|
|
1684
1699
|
args: [{ selector: 'crispr-form', changeDetection: ChangeDetectionStrategy.OnPush, template: "<form\n class=\"crispr-form\"\n [ngClass]=\"config.classes\"\n [formGroup]=\"form\"\n (ngSubmit)=\"handleSubmit()\"\n [autocomplete]=\"config.autocomplete || 'off'\"\n [errorDictionary]=\"config.errorDictionary\"\n #ngFormElement=\"ngForm\">\n\n <ng-container\n *ngFor=\"let field of config.fields;\"\n crisprField\n [value]=\"value | initialControlValue : field\"\n [config]=\"field\"\n [group]=\"form\">\n </ng-container>\n <!-- Hidden button, programmatically clicked when crispr form triggerSubmit function called.\n Uses a hidden button with type=\"submit\" because it will trigger both native form submit event\n (which the error handler has to listen for) and ngSubmit event -->\n <button #submitTrigger class=\"submit-trigger\" type=\"submit\">\n </button>\n</form>\n", styles: [".submit-trigger{display:none}\n"] }]
|