From fb0dd4416d87d38391f89926c83c7d9636e1e34a Mon Sep 17 00:00:00 2001 From: erdemcaygor Date: Wed, 8 Oct 2025 14:10:00 +0300 Subject: [PATCH] refactoring --- .../dynamic-form-field.component.html | 182 +++++++++--------- .../dynamic-form-field.component.ts | 9 +- .../src/dynamic-form.component.html | 27 +++ .../src/dynamic-form.component.ts | 11 +- 4 files changed, 132 insertions(+), 97 deletions(-) create mode 100644 npm/ng-packs/packages/components/dynamic-form/src/dynamic-form.component.html diff --git a/npm/ng-packs/packages/components/dynamic-form/src/dynamic-form-field/dynamic-form-field.component.html b/npm/ng-packs/packages/components/dynamic-form/src/dynamic-form-field/dynamic-form-field.component.html index c67d82a105..a122ad9315 100644 --- a/npm/ng-packs/packages/components/dynamic-form/src/dynamic-form-field/dynamic-form-field.component.html +++ b/npm/ng-packs/packages/components/dynamic-form/src/dynamic-form-field/dynamic-form-field.component.html @@ -1,92 +1,94 @@ -
+@if (visible()) { +
- @if (field().type === 'text') { - -
- - - -
- } @else if (field().type === 'select') { - -
- - - -
- } @else if (field().type === 'checkbox') { - -
- - - -
- } @else if (field().type === 'email') { - -
- - - -
- } @else if (field().type === 'textarea') { - -
- - - -
- } -
- + +
+ } + + +} diff --git a/npm/ng-packs/packages/components/dynamic-form/src/dynamic-form-field/dynamic-form-field.component.ts b/npm/ng-packs/packages/components/dynamic-form/src/dynamic-form-field/dynamic-form-field.component.ts index 18c312f20c..1aa89c31f0 100644 --- a/npm/ng-packs/packages/components/dynamic-form/src/dynamic-form-field/dynamic-form-field.component.ts +++ b/npm/ng-packs/packages/components/dynamic-form/src/dynamic-form-field/dynamic-form-field.component.ts @@ -1,7 +1,9 @@ import { ChangeDetectionStrategy, + ChangeDetectorRef, Component, forwardRef, + inject, InjectionToken, input, } from '@angular/core'; @@ -32,12 +34,14 @@ const DYNAMIC_FORM_FIELD_CONTROL_VALUE_ACCESSOR = { export class DynamicFormFieldComponent implements ControlValueAccessor { field = input.required(); - isVisible = input(true); + visible = input(true); disabled = false; value: any; + readonly changeDetectorRef = inject(ChangeDetectorRef); writeValue(value: any[]): void { - // + this.value = value; + this.changeDetectorRef.markForCheck(); } registerOnChange(fn: any): void { @@ -50,6 +54,7 @@ export class DynamicFormFieldComponent implements ControlValueAccessor { setDisabledState(isDisabled: boolean): void { this.disabled = isDisabled; + this.changeDetectorRef.markForCheck(); } private onChange: (value: any) => void = () => {}; diff --git a/npm/ng-packs/packages/components/dynamic-form/src/dynamic-form.component.html b/npm/ng-packs/packages/components/dynamic-form/src/dynamic-form.component.html new file mode 100644 index 0000000000..b1a5c15ebd --- /dev/null +++ b/npm/ng-packs/packages/components/dynamic-form/src/dynamic-form.component.html @@ -0,0 +1,27 @@ +
+ @for (field of sortedFields; track field.key) { +
+
+ + +
+
+ } +
+ + +
+
diff --git a/npm/ng-packs/packages/components/dynamic-form/src/dynamic-form.component.ts b/npm/ng-packs/packages/components/dynamic-form/src/dynamic-form.component.ts index 8fde9f5792..8aa11ade97 100644 --- a/npm/ng-packs/packages/components/dynamic-form/src/dynamic-form.component.ts +++ b/npm/ng-packs/packages/components/dynamic-form/src/dynamic-form.component.ts @@ -1,5 +1,5 @@ -import { ChangeDetectionStrategy, Component, input, output, inject } from '@angular/core'; -import { FormGroup } from '@angular/forms'; +import { ChangeDetectionStrategy, Component, input, output, inject, OnInit } from '@angular/core'; +import { FormBuilder, FormGroup, ReactiveFormsModule } from '@angular/forms'; import { CommonModule } from '@angular/common'; import { DynamicFormService } from './dynamic-form.service'; import { FormFieldConfig } from './dynamic-form.models'; @@ -7,11 +7,12 @@ import { DynamicFormFieldComponent } from './dynamic-form-field'; @Component({ selector: 'abp-dynamic-form', - template: ``, - changeDetection: ChangeDetectionStrategy.OnPush + templateUrl: './dynamic-form.component.html', + changeDetection: ChangeDetectionStrategy.OnPush, + imports: [CommonModule, DynamicFormFieldComponent, ReactiveFormsModule], }) -export class DynamicFormComponent { +export class DynamicFormComponent implements OnInit { fields = input([]); submitButtonText = input('Submit'); formSubmit = output();