Conversation
|
Thanks for contributions. feature is very good but support for nested forms should be added. |
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new dynamic form component for the ABP Angular framework that allows developers to create forms dynamically using configuration objects. The component supports various field types, validation, conditional logic, and custom components.
- Adds a comprehensive dynamic form system with support for text, email, select, checkbox, textarea, and date field types
- Implements conditional field visibility and enablement based on other field values
- Provides validation configuration with custom error messages and built-in Angular validators
Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| npm/ng-packs/tsconfig.base.json | Adds TypeScript path mapping for the new dynamic-form package |
| npm/ng-packs/packages/components/dynamic-form/src/public-api.ts | Exports public API for the dynamic form components and models |
| npm/ng-packs/packages/components/dynamic-form/src/dynamic-form.service.ts | Service for creating form groups and handling validation logic |
| npm/ng-packs/packages/components/dynamic-form/src/dynamic-form.models.ts | Type definitions for form field configuration and validation |
| npm/ng-packs/packages/components/dynamic-form/src/dynamic-form.component.ts | Main dynamic form component with conditional logic and form management |
| npm/ng-packs/packages/components/dynamic-form/src/dynamic-form.component.scss | Styling for the dynamic form layout |
| npm/ng-packs/packages/components/dynamic-form/src/dynamic-form.component.html | Template for rendering dynamic form fields and actions |
| npm/ng-packs/packages/components/dynamic-form/src/dynamic-form-field/index.ts | Barrel export for form field components |
| npm/ng-packs/packages/components/dynamic-form/src/dynamic-form-field/dynamic-form-field.component.ts | Individual form field component with validation and error handling |
| npm/ng-packs/packages/components/dynamic-form/src/dynamic-form-field/dynamic-form-field.component.scss | Styling for individual form fields |
| npm/ng-packs/packages/components/dynamic-form/src/dynamic-form-field/dynamic-form-field.component.html | Template for rendering different field types |
| npm/ng-packs/packages/components/dynamic-form/src/dynamic-form-field/dynamic-form-field-host.component.ts | Host component for dynamic custom field components |
| npm/ng-packs/packages/components/dynamic-form/ng-package.json | Package configuration for the dynamic form library |
| npm/ng-packs/apps/dev-app/src/server.ts | Removes conditional check for TLS rejection in development |
| npm/ng-packs/apps/dev-app/src/app/home/home.component.ts | Adds example usage of the dynamic form component |
| npm/ng-packs/apps/dev-app/src/app/home/home.component.html | Updates template to include dynamic form demonstration |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| const validator = this.field().validators.find( | ||
| v => v.type.toLowerCase() === key.toLowerCase(), | ||
| ); | ||
| console.log(this.field().validators, key); |
There was a problem hiding this comment.
Remove console.log statement used for debugging. This should not be present in production code.
| console.log(this.field().validators, key); |
| } | ||
|
|
||
| submit() { | ||
| console.log(this.dynamicForm.valid, this.dynamicForm.value); |
There was a problem hiding this comment.
Remove console.log statement used for debugging. This should not be present in production code.
| console.log(this.dynamicForm.valid, this.dynamicForm.value); | |
| return `Maximum length is ${this.control.errors[key].requiredLength}`; | ||
| return `${this.field().label} is invalid due to ${key} validation.`; | ||
| }); | ||
| } |
There was a problem hiding this comment.
The errors getter method doesn't return anything when there are no errors. It should return an empty array to ensure consistent return type.
| } | |
| } | |
| return []; |
| if (environment.production === false) { | ||
| process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0"; | ||
| } | ||
| process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0"; |
There was a problem hiding this comment.
Setting NODE_TLS_REJECT_UNAUTHORIZED to '0' disables TLS certificate validation globally, which is a security risk. This should be conditional for development environments only or use a more targeted approach.
| process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0"; | |
| if (!environment.production) { | |
| process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0"; | |
| } |
| } | ||
|
|
||
| get errors(): string[] { | ||
| if (this.control && this.control.errors) { |
There was a problem hiding this comment.
We can add a default return type here like this:
if (!this.control?.errors) return [];|
|
||
| const options = this.field().options; | ||
|
|
||
| if (options?.url) { |
There was a problem hiding this comment.
We can extract these operations for clarity maybe like this
private initializeOptions(): void {
const options = this.field().options;
if (options?.url) {
this.options$ = this.dynamicFormService.getOptions(options.url, options.apiName);
} else if (options?.defaultValues?.length) {
this.options$ = of(this.mapDefaultOptions(options));
} else {
this.options$ = of([]);
}
}
private mapDefaultOptions(options: OptionProps): { key: string; value: any }[] {
return options.defaultValues.map(item => ({
key: item[options.valueProp || 'key'] || item,
value: item[options.labelProp || 'value'] || item
}));
}
...acks/packages/components/dynamic-form/src/dynamic-form-field/dynamic-form-field.component.ts
Show resolved
Hide resolved
|
I agree with @sumeyyeKurtulus 's suggestions. |
Resolves #23891
TODO
Config Interfaces
Example Usage