Maps a form field type string onto the corresponding form widget component type.
string
, defaultValue: Type<any>
= this.defaultValue
): DynamicComponentResolveFunction
string
- The type whose resolver you wantType<any>
- Default type returned for types that are not yet mappedDynamicComponentResolveFunction
- Resolver functionFunction
, override: boolean
= false
)Function
- boolean
- DynamicComponentModel
, defaultValue: Type<any>
= this.defaultValue
): Type<any>
DynamicComponentModel
- Form field model for the field to renderType<any>
- Default type returned for field types that are not yet mapped.Type<any>
- Component typestring
, resolver: DynamicComponentResolveFunction
, override: boolean
= true
)string
- The type whose resolver you want to setDynamicComponentResolveFunction
- The new resolver functionboolean
- The new resolver will only replace an existing one if this parameter is trueThe Form
Field component uses this service to choose which widget to use to render an instance of a
form field. The Form
Field model stores the field type name as a string (see the table below).
The Form
Rendering service maintains a mapping between each type name and
a corresponding DynamicComponentResolveFunction
. The function takes a FormFieldModel
object as its argument and
uses the data from the object to determine which widget should be used to render the field.
In some cases, the field type string alone is enough to determine the widget type and so the function just returns the type directly:
let customResolver: DynamicComponentResolveFunction = () => CustomWidgetComponent;
formRenderingService.setComponentTypeResolver('text', customResolver, true);
In other cases, the function may need to choose the widget dynamically based on specific values in the form data:
let customResolver: DynamicComponentResolveFunction = (field: FormFieldModel): Type<{}> => { if (field) { let params = field.params; } return UnknownWidgetComponent; }; formRenderingService.setComponentTypeResolver('text', customResolver, true);
The Form
Rendering service is initialized with the mapping shown in the table below:
Stencil name | Field type string | Component type |
---|---|---|
Amount | "amount" | AmountWidgetComponent |
Attach | "upload" | AttachWidgetComponent or UploadWidgetComponent (based on metadata) |
Checkbox | "boolean" | CheckboxWidgetComponent |
Date | "date" | DateWidgetComponent |
Display text | "readonly-text" | DisplayTextWidgetComponentComponent |
Display Rich text | "display-rich-text" | DisplayRichTextWidgetComponent |
Display value | "readonly" | DisplayValueWidgetComponent |
Dropdown | "dropdown" | DropdownWidgetComponent |
Dynamic table | "dynamic-table" | DynamicTableWidgetComponent |
Group of people | "functional-group" | FunctionalGroupWidgetComponent |
Header | "group" | ContainerWidgetComponent |
Hyperlink | "hyperlink" | HyperlinkWidgetComponent |
Multi-line text | "multi-line-text" | MultilineTextWidgetComponentComponent |
Number | "integer" | NumberWidgetComponent |
People | "people" | PeopleWidgetComponent |
Radio buttons | "radio-buttons" | RadioButtonsWidgetComponent |
Text | "text" | TextWidgetComponent |
Typeahead | "typeahead" | TypeaheadWidgetComponent |
You can add new items to the mapping or replace existing items in order to customize the way fields are rendered.
You can use the setComponentTypeResolver
method to add a new ComponentTypeResolver function for a
particular type string. You can also replace the resolver for a type that already exists in the mapping
if you set the override
parameter to 'true':
formRenderingService.setComponentTypeResolver('text', newResolver, true);
You would typically use this to replace an existing widget with your own custom version that implements a modified layout or responds differently when the data is entered. See the Form Extensibility and Customisation guide for further details and examples of this technique.
© 2023 Alfresco Software, Inc. All Rights Reserved.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.