Build a custom widget or field plugin
Section titled “Build a custom widget or field plugin”This how-to is for developers who need a page widget or a field control that the built-in ones do not cover. You will learn which kinds of plugin exist, which base classes and metadata each one needs, how to register it so builders can pick it, and how to ship it. Two minimal worked examples — a widget and a field control — are modelled on plugins already in the code.
You need:
- A checkout of the web frontend (an Nx workspace with Angular) that you can run locally. See Run the platform from source.
- Working knowledge of Angular standalone components, signals and
ControlValueAccessor. - A way to build and deploy your own web image, and access to the deployment’s
org-config.json(for widgets).
How plugins work
Section titled “How plugins work”Every widget and field control — built-in or yours — is a lazily loaded Angular component with a name. Two things make a component usable:
- An expose: the name mapped to a loader that imports the component.
- Metadata: what the builder shows (its label and icon), what kind of component it is and which component it pairs with.
A plugin module config (InternalPluginModuleConfig from
@osos/shared/types) holds both lists:
export interface InternalPluginModuleConfig { exposes: Array<{ name: string; loadModuleProxy: () => PromiseLike<{ default: ModuleProxy<unknown> }> }>; metadata: ComponentRegisterDataModel[];}At start-up the web app imports each plugin module config, registers its exposes with the component factory and stores its metadata. When a page or a form needs a component, the platform looks it up by name and loads it.
The in-repo plugin packs live in apps/core/src/app/shared/custom-plugins/:
| Pack | Contains |
|---|---|
composite-summaries-widget (root index.ts) | The Composite Summaries widget. |
diwan | Widgets such as QR code, quick counters, quick summaries, links grid, footer, attendance, v-card and sign-in. |
gate | Timeline slider widgets. |
task-mgmt | Widgets such as welcome title, quick links, hero slider and wiki, and an entry template. |
The built-in field controls are registered the same way, from
libs/shared/dynamic-fields.
Plugin kinds
Section titled “Plugin kinds”The kind is the metadata’s type (ComponentType from @osos/shared/types). The
base classes come from @osos/shared/plugin-cdk — always import from that barrel;
deep imports into the library do not resolve.
| Kind | ComponentType | Base class | Metadata helper |
|---|---|---|---|
| Widget (shown on a page) | WidgetComponent | DynamicWidgetViewBase<TConfig> | createWidgetComponentMetadata |
| Widget settings (in the widget dialog) | WidgetConfigComponent | DynamicWidgetConfigBase<TConfig> | — (named by the widget’s metadata) |
| Field control, edit | FieldControlEditComponent | DynamicComponentBase<DataType, ValueType> | createComponentMetadata |
| Field control, read-only | FieldControlViewComponent | DynamicFieldControlViewBase<DataType, ValueType> | createComponentMetadata |
| Field block | FieldBlockEditComponent, FieldBlockViewComponent | DynamicFieldBlockEditBase | createFieldBlockComponentMetadata |
| Entry template | EntryTemplateEditComponent, EntryTemplateViewComponent, EntriesListTemplateViewComponent | DynamicEditEntryTemplateBase, DynamicEntryViewTemplateBase, DynamicListViewTemplateBase, DynamicEntryTemplateViewBase | createTemplateComponentMetadata |
The kit also contains DynamicActionBase and DynamicEventConfigBase for the
configuration screens of automations. Those are wired directly in the platform’s
own code, not through plugin registration.
This page covers widgets and field controls.
Build a widget plugin
Section titled “Build a widget plugin”A widget is a pair: a view component that renders on the page and a
config component that the builder fills in. The config component’s value is
saved as the widget’s options, and the view reads it back as this.config.
The example below is a Greeting widget, modelled on the task-mgmt Welcome
Title widget (task-mgmt/widgets/welcom-title-view and welcom-title-config).
1. Lay out the files
Section titled “1. Lay out the files”apps/core/src/app/shared/custom-plugins/acme/ index.ts plugin-module.config.ts widgets/ metadata.ts greeting/ greeting-config.model.ts metadata.ts view/greeting-view.component.ts view/greeting-view.proxy.ts config/greeting-config.component.ts config/greeting-config.proxy.ts2. Define the settings
Section titled “2. Define the settings”export interface GreetingConfig { message: string; showDate: boolean;}3. Write the view
Section titled “3. Write the view”import { DatePipe } from '@angular/common';import { ChangeDetectionStrategy, Component } from '@angular/core';import { DynamicWidgetViewBase } from '@osos/shared/plugin-cdk';import { GreetingConfig } from '../greeting-config.model';
@Component({ selector: 'acme-greeting-view', changeDetection: ChangeDetectionStrategy.OnPush, imports: [DatePipe], template: ` <section class="p-4"> <h3 class="my-0">{{ config.message || 'Welcome' }}</h3> @if (config.showDate) { <p>{{ today | date: 'fullDate' }}</p> } </section> `,})export class AcmeGreetingViewComponent extends DynamicWidgetViewBase<GreetingConfig> { readonly today = new Date();}DynamicWidgetViewBase gives you these inputs, set by the page:
| Member | Type | Meaning |
|---|---|---|
widget | GenericViewWidgetPresenterModel | undefined | The placed widget: component, title, description, icon, displayOptions, options. |
config | TConfig | Shortcut for widget.options — your saved settings ({} until set). |
preview | boolean | The widget is shown in the page designer. |
readonly | boolean | The page is shown read-only. |
hasGroupContainer | boolean | The widget sits inside a section or column. |
isAutoRefresh, autoRefreshInterval | boolean, number | undefined | The page’s auto-refresh setting. |
destroy$ | ReplaySubject<void> | Emits when the widget is destroyed. |
4. Write the settings form
Section titled “4. Write the settings form”The config component is a ControlValueAccessor and a Validator: the widget
dialog writes the saved settings in and reads every change back.
import { ChangeDetectionStrategy, Component, DestroyRef, forwardRef, inject, OnInit } from '@angular/core';import { takeUntilDestroyed } from '@angular/core/rxjs-interop';import { FormBuilder, NG_VALUE_ACCESSOR, ReactiveFormsModule, ValidationErrors } from '@angular/forms';import { DynamicWidgetConfigBase } from '@osos/shared/plugin-cdk';import { GreetingConfig } from '../greeting-config.model';
@Component({ selector: 'acme-greeting-config', changeDetection: ChangeDetectionStrategy.OnPush, imports: [ReactiveFormsModule], providers: [ { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => AcmeGreetingConfigComponent), multi: true, }, ], template: ` <div class="flex flex-col gap-2" [formGroup]="form"> <label for="greeting-message">Message</label> <input id="greeting-message" type="text" formControlName="message" /> <label> <input type="checkbox" formControlName="showDate" /> Show today's date </label> </div> `,})export class AcmeGreetingConfigComponent extends DynamicWidgetConfigBase<GreetingConfig> implements OnInit{ private readonly fb = inject(FormBuilder); private readonly destroyRef = inject(DestroyRef);
readonly form = this.fb.nonNullable.group({ message: '', showDate: true, });
ngOnInit(): void { this.form.valueChanges .pipe(takeUntilDestroyed(this.destroyRef)) .subscribe((value) => this._onChange?.(value as GreetingConfig)); }
writeValue(value: GreetingConfig): void { if (value) { this.form.patchValue(value, { emitEvent: false }); } }
validate(): ValidationErrors | null { return this.form.controls.message.value ? null : { messageRequired: true }; }}DynamicWidgetConfigBase provides componentModel (your widget’s registered
metadata), _onChange, _onTouched, _onValidationChange, disabled,
readonly and destroy$. You implement writeValue and validate; while
validate returns errors, the dialog’s DONE button stays disabled.
5. Add the proxies
Section titled “5. Add the proxies”Each loadable component has a proxy file whose default export is a ModuleProxy.
import { ModuleProxy } from '@osos/shared/types';import { AcmeGreetingViewComponent } from './greeting-view.component';
const moduleProxy: ModuleProxy<AcmeGreetingViewComponent> = { component: AcmeGreetingViewComponent,};
export default moduleProxy;Write config/greeting-config.proxy.ts the same way for
AcmeGreetingConfigComponent.
6. Describe it with metadata
Section titled “6. Describe it with metadata”import { createWidgetComponentMetadata } from '@osos/shared/plugin-cdk';import { ComponentType } from '@osos/shared/types';
export default createWidgetComponentMetadata({ customPlugin: true, componentName: 'ACME/GreetingWidget', type: ComponentType.WidgetComponent, name: { en: 'Greeting', ar: 'ترحيب' }, icon: 'icon-title', preferredPairedComponents: [ { name: 'ACME/GreetingWidgetConfig', type: ComponentType.WidgetConfigComponent }, ], options: { defaultOptions: { display: { width: 12 } }, validations: { width: { enabled: true, options: { availableWidths: [6, 8, 12] } }, }, },});| Key | Meaning |
|---|---|
componentName | The widget’s name. It must equal the view’s expose name. In-repo packs prefix it (TMGMT/, GATE/, DIWAN/). |
customPlugin | true hides the widget until the deployment lists it in PAGE_CUSTOM_PLUGIN (below). |
name, icon | The label and icon in the page designer’s Widgets panel. |
preferredPairedComponents | The settings component, by its expose name, with type WidgetConfigComponent. |
options.defaultOptions.display.width | The starting width in columns. |
options.validations.width.options.availableWidths | The widths a builder may choose. |
Collect the pack’s metadata in widgets/metadata.ts:
import { ComponentRegisterDataModel } from '@osos/shared/types';import greetingWidgetMetadata from './greeting/metadata';
export const DYNAMIC_WIDGETS_METADATA = Array<ComponentRegisterDataModel>( greetingWidgetMetadata,);7. Write the plugin module config
Section titled “7. Write the plugin module config”import { InternalPluginModuleConfig } from '@osos/shared/types';import { DYNAMIC_WIDGETS_METADATA } from './widgets/metadata';
const pluginModuleConfig: InternalPluginModuleConfig = { exposes: [ { name: 'ACME/GreetingWidget', loadModuleProxy: () => import('./widgets/greeting/view/greeting-view.proxy'), }, { name: 'ACME/GreetingWidgetConfig', loadModuleProxy: () => import('./widgets/greeting/config/greeting-config.proxy'), }, ], metadata: DYNAMIC_WIDGETS_METADATA,};
export default pluginModuleConfig;import PluginModuleConfig from './plugin-module.config';
export { PluginModuleConfig };8. Register the pack
Section titled “8. Register the pack”Add your pack to the list the web app loads at start-up, in
apps/core/src/app/app.component.ts, method _initInternalPlugins():
merge( import('@osos/shared/dynamic-fields'), import('@osos/feature/entry-templates'), import('./shared/dynamic-widgets-components'), import('./shared/custom-plugins/task-mgmt'), import('./shared/custom-plugins/gate'), import('./shared/custom-plugins/diwan'), import('./shared/custom-plugins'), import('./shared/custom-plugins/acme'), // your pack)Each imported module must export PluginModuleConfig.
9. Switch the widget on for the deployment
Section titled “9. Switch the widget on for the deployment”A widget whose metadata says customPlugin: true appears only when its
componentName is listed in PAGE_CUSTOM_PLUGIN in the web app’s
org-config.json:
{ "PAGE_CUSTOM_PLUGIN": ["ACME/GreetingWidget"]}The repository’s apps/core/src/org-config.json lists the in-repo widgets. In a
Helm deployment the file comes from the chart value web.orgConfig, whose default
has no PAGE_CUSTOM_PLUGIN — add the key there, next to the branding keys. See
Helm chart.
Build a field-control plugin
Section titled “Build a field-control plugin”A field control is also a pair: an edit component for forms and a view component for details and lists. Once registered, the edit component appears as a new field type in the entity designer, and the field stores which edit and view components it uses.
The example below is a Star rating control for a Number field, modelled on the
built-in Year control (libs/shared/dynamic-fields/.../components/year and
view-dynamic-components/view-year).
1. Write the edit component
Section titled “1. Write the edit component”import { ChangeDetectionStrategy, Component } from '@angular/core';import { AbstractControl, ValidationErrors, Validators } from '@angular/forms';import { DynamicComponentBase, NumberDataType } from '@osos/shared/plugin-cdk';import { DataTypeEnum } from '@osos/shared/types';
@Component({ selector: 'acme-star-rating', changeDetection: ChangeDetectionStrategy.OnPush, template: ` @if (field) { <div class="flex gap-1" [class]="styleClass" [attr.data-testid]="uid"> @for (star of stars; track star) { <button type="button" [disabled]="disabled || elementDisabled || readOnly" [attr.aria-label]="star + ' of 5'" (click)="select(star)" (blur)="_onTouched?.()" >{{ star <= (value ?? 0) ? '★' : '☆' }}</button> } </div> } `,})export class AcmeStarRatingComponent extends DynamicComponentBase< DataTypeEnum.Number, NumberDataType> { readonly stars = [1, 2, 3, 4, 5];
writeValue(value: NumberDataType): void { this.value = typeof value === 'number' ? value : null; }
validate(control: AbstractControl): ValidationErrors | null { const mustFill = this.required ?? !!this.field?.validations?.required?.enabled; return mustFill ? Validators.required(control) : null; }
select(star: number): void { this.value = star; this._onChange?.(star); this._onTouched?.(); }}What DynamicComponentBase gives you, set by the form:
| Member | Type | Meaning |
|---|---|---|
value | ValueType | The current value (signal-backed; setting it re-renders). |
field | FieldPresenterModel | undefined | The field: normalizedName, name, dataType, validations, and renderOptions.editComponent.options for your own options. |
mode | 'designer' | 'entry' | undefined | Shown in the entity designer, or on a real form. |
required | boolean | undefined | Forces required on or off; undefined means “use field.validations.required”. |
readOnly, elementDisabled, disabled | boolean | Whether the person may change the value. |
placeholder, styleClass, uid | string | Placeholder text, CSS classes to apply, and a unique id for inputId/test ids. |
ctrlErrorsTemplateRef | TemplateRef | undefined | A template that renders the field’s errors, if you want to show them. |
displayConfig | { mode: 'comfort' | 'compact' } | Density. |
searchModeEnabled | boolean | undefined | The control is used as a search filter; report changes with _mappedSearchValueChange instead of _onChange (see the Year control). |
_onChange, _onTouched | functions | Call them when the value changes and when the control is left. |
You implement writeValue(value) and validate(control). Emit a value in the
shape the field’s data type uses — for DataTypeEnum.Number that is
NumberDataType (number, or a pair for ranges).
2. Write the read-only component
Section titled “2. Write the read-only component”import { ChangeDetectionStrategy, Component } from '@angular/core';import { DynamicFieldControlViewBase, NumberDataType } from '@osos/shared/plugin-cdk';import { DataTypeEnum } from '@osos/shared/types';
@Component({ selector: 'acme-view-star-rating', changeDetection: ChangeDetectionStrategy.OnPush, template: ` @if (rating) { <span [class]="styleClass" [attr.aria-label]="rating + ' of 5'"> @for (star of stars; track star) { {{ star <= rating ? '★' : '☆' }} } </span> } `,})export class AcmeViewStarRatingComponent extends DynamicFieldControlViewBase< DataTypeEnum.Number, NumberDataType> { readonly stars = [1, 2, 3, 4, 5];
get rating(): number { return typeof this.value === 'number' ? this.value : 0; }}DynamicFieldControlViewBase gives you value, field, displayConfig,
viewType (where it is shown), fieldControlConfig, styleClass and
searchValues.
Add a proxy file for each component, exactly as for the widget.
3. Describe both with metadata
Section titled “3. Describe both with metadata”import { createComponentMetadata } from '@osos/shared/plugin-cdk';import { ComponentType, DataTypeEnum } from '@osos/shared/types';
export const STAR_RATING_METADATA = createComponentMetadata({ specificationVersion: 1, name: { en: 'Star rating', ar: 'تقييم بالنجوم' }, componentName: 'ACME/StarRatingComponent', dataTypes: [DataTypeEnum.Number], type: ComponentType.FieldControlEditComponent, componentOptions: [], preferredPairedComponents: [ { name: 'ACME/ViewStarRatingComponent', type: ComponentType.FieldControlViewComponent }, ], icon: 'number',});
export const VIEW_STAR_RATING_METADATA = createComponentMetadata({ specificationVersion: 1, name: { en: 'View-star-rating', ar: 'عرض التقييم بالنجوم' }, componentName: 'ACME/ViewStarRatingComponent', dataTypes: [DataTypeEnum.Number], type: ComponentType.FieldControlViewComponent, componentOptions: [], preferredPairedComponents: [ { name: 'ACME/StarRatingComponent', type: ComponentType.FieldControlEditComponent }, ], icon: 'number',});When a builder adds the field, the platform takes the data type from
dataTypes[0], the edit component from componentName and the view component
from the first entry of preferredPairedComponents. Other keys you may set
mirror the built-in controls: supportDefaultValue (default true),
supportUniqueOption, supportSearchable, fieldQueryOptions and
displayOptions.
createComponentMetadata always sets customPlugin: false, so a field control is
available as soon as it is registered — it does not use PAGE_CUSTOM_PLUGIN.
4. Register it
Section titled “4. Register it”Put both exposes and both metadata entries in a plugin module config — your own
pack’s (as in step 7) or a new one — and make sure the
pack is in _initInternalPlugins() (step 8).
exposes: [ { name: 'ACME/StarRatingComponent', loadModuleProxy: () => import('./fields/star-rating/star-rating.proxy') }, { name: 'ACME/ViewStarRatingComponent', loadModuleProxy: () => import('./fields/star-rating/view-star-rating.proxy') },],metadata: [...DYNAMIC_WIDGETS_METADATA, STAR_RATING_METADATA, VIEW_STAR_RATING_METADATA],Ship the plugin
Section titled “Ship the plugin”- Run the web app locally (
pnpm start) and try the plugin — see Use it in the builder. - Build the web app (
pnpm build) and produce your web image the way your pipeline does. - Deploy the new image.
- For a widget, add its
componentNametoPAGE_CUSTOM_PLUGINin the deployment’sorg-config.json(web.orgConfigin Helm). A field control needs no extra step.
Use it in the builder
Section titled “Use it in the builder”A widget.
- Open a page: Administration › Applications › Pages, then the page (or New Page).
- On the Content tab, find your widget by its
namein the Widgets panel and add it. - In the widget dialog, your settings component appears on the Content tab, next to General. Fill it in and select DONE.
- Save the page.
See Pages and widgets.
A field control.
- Open the entity’s designer: Administration › Applications › Data Entities, then Edit Entity on the entity card.
- On the Structure tab, your control is listed by its
namein the Fields palette. Drag it onto the form. - Configure and Save as for any field.
See Create and design an entity.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Likely cause |
|---|---|
| The widget is not in the Widgets panel. | Its componentName is missing from PAGE_CUSTOM_PLUGIN, or the pack is not in _initInternalPlugins(). |
The browser console shows [appDynamicWidgetView] Unknown or failed to load component: "…". | The metadata’s componentName does not match an expose name, or the proxy has no default export with component. |
[appDynamicWidgetConfig] Unknown or failed to load component when opening the widget dialog. | preferredPairedComponents names a settings component that is not exposed. |
| The field type is missing from the Fields palette. | The metadata’s type is not FieldControlEditComponent, or the pack is not registered. |
| A field shows an empty value in details or lists. | The view component’s name in preferredPairedComponents[0] is not exposed. |
See also
Section titled “See also”- Pages and widgets
- Field types
- Frontend architecture
- Run the platform from source
- Run JavaScript on forms and lists — for small behaviour that needs no rebuild
Platform 1.10.0 · Backend 1.11.0-alpha.11 · Frontend 1.11.0-alpha.6 · Mobile 1.10.2 · Chart 1.11.8 · Gateway 2.6.11 · MCP 0.2.0 · Grafana DS 1.2.0Docs build 2026-11-27