* * improve docs * * assets fixed * * links fixed * * versions fixed * * assets added * * fix links * Update docs/user-guide/aae-extensions.md Co-authored-by: Mark Hulbert <39801222+m-hulbert@users.noreply.github.com> * Update docs/user-guide/aae-extensions.md Co-authored-by: Mark Hulbert <39801222+m-hulbert@users.noreply.github.com> * Update docs/user-guide/aae-extensions.md Co-authored-by: Mark Hulbert <39801222+m-hulbert@users.noreply.github.com> * Update docs/user-guide/aae-extensions.md Co-authored-by: Mark Hulbert <39801222+m-hulbert@users.noreply.github.com> * Update docs/user-guide/aae-extensions.md Co-authored-by: Mark Hulbert <39801222+m-hulbert@users.noreply.github.com> * Update docs/user-guide/aae-extensions.md Co-authored-by: Mark Hulbert <39801222+m-hulbert@users.noreply.github.com> * Update docs/user-guide/aae-extensions.md Co-authored-by: Mark Hulbert <39801222+m-hulbert@users.noreply.github.com> * Update docs/user-guide/aae-extensions.md Co-authored-by: Mark Hulbert <39801222+m-hulbert@users.noreply.github.com> * Update docs/user-guide/aae-extensions.md Co-authored-by: Mark Hulbert <39801222+m-hulbert@users.noreply.github.com> * Update docs/user-guide/aae-extensions.md Co-authored-by: Mark Hulbert <39801222+m-hulbert@users.noreply.github.com> * Update docs/user-guide/aae-extensions.md Co-authored-by: Mark Hulbert <39801222+m-hulbert@users.noreply.github.com> * Update docs/user-guide/aae-extensions.md Co-authored-by: Mark Hulbert <39801222+m-hulbert@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Mark Hulbert <39801222+m-hulbert@users.noreply.github.com> * * example fixed * * minor changes * Make stencils document step-based Co-authored-by: Mark Hulbert <39801222+m-hulbert@users.noreply.github.com> Co-authored-by: Mark Hulbert <mark.hulbert@alfresco.com>
5.5 KiB
Title, Added
Title | Added |
---|---|
Form Extensibility for AAE Form Widget | v4.1.0 |
Form Extensibility for AAE Form Widget
This page describes how you can customize ADF forms to your own specification.
Contents
There are two ways to customize the form
- Replace default form widgets with custom components
- Replace custom form widget with custom components
Replace default form widgets with AAE form widgets
This is an example of replacing the standard Text
widget with a custom component for all AAE forms rendered within the <adf-form>
component.
-
Create a simple form with some
Text
widgets:Every custom widget component must inherit the
WidgetComponent
class in order to function properly:import { Component } from '@angular/core'; import { WidgetComponent } from '@alfresco/adf-core'; @Component({ selector: 'custom-editor', template: ` <div style="color: red">Look, I'm a AAE custom editor!</div> ` }) export class CustomEditorComponent extends WidgetComponent {}
-
Add it to the application module or any custom module that is imported into the application one:
import { NgModule } from '@angular/core'; import { CustomEditorComponent } from './custom-editor.component'; @NgModule({ declarations: [ CustomEditorComponent ], exports: [ CustomEditorComponent ] }) export class CustomEditorsModule {}
-
Every custom widget component should be added into the the collections
declarations
andexports
. If you decided to store custom widgets in a separate dedicated module (and optionally as a separate re-distributable library) don't forget to import it into the main application:@NgModule({ imports: [ // ... CustomEditorsModule // ... ], providers: [], bootstrap: [ AppComponent ] }) export class AppModule {}
-
Import the
FormRenderingService
into any of your Views and override the default mapping, for example:import { Component } from '@angular/core'; import { CustomEditorComponent } from './custom-editor.component'; @Component({...}) export class MyView { constructor(formRenderingService: FormRenderingService) { this.formRenderingService.register({ 'text': () => CustomEditorComponent }, true); } }
-
At runtime the form should look similar to the following:
Replace custom form widgets with custom components
This is an example of rendering custom form widgets using custom Angular components.
Create a custom form widget
To begin, create a basic form widget and call it demo-widget
:
Note: The type
is important as it will become the field type
when the form is rendered.
You can now design a form that uses your custom form widget:
Create a custom widget
When displayed in a task, the field will look similar to the following:
To render the missing content:
-
Create an Angular component:
import { Component } from '@angular/core'; import { WidgetComponent } from '@alfresco/adf-core'; @Component({ selector: 'app-demo-widget', template: `<div style="color: green">ADF version of custom form widget</div>` }) export class DemoWidgetComponent extends WidgetComponent {}
-
Place it inside the custom module:
import { NgModule } from '@angular/core'; import { DemoWidgetComponent } from './demo-widget.component'; @NgModule({ declarations: [ DemoWidgetComponent ], exports: [ DemoWidgetComponent ] }) export class CustomWidgetsModule {}
-
Import it into your Application Module:
@NgModule({ imports: [ // ... CustomWidgetsModule // ... ], providers: [], bootstrap: [ AppComponent ] }) export class AppModule {}
-
Import the
FormRenderingService
in any of your Views and provide the new mapping:import { Component } from '@angular/core'; import { DemoWidgetComponent } from './demo-widget.component'; @Component({...}) export class MyView { constructor(formRenderingService: FormRenderingService) { this.formRenderingService.register({ 'custom-editor': () => DemoWidgetComponent }); } }
At runtime you should now see your custom Angular component rendered in place of the original form widgets: