Logic

Form Controller Extensibility

Learn how to extend and customize Form Controller for your specific needs

Extensibility

Form Controller has been designed with extensibility in mind. The class-based architecture allows you to create custom form controllers with specialized behavior by extending the base FormControllerClass.

Key Extensibility Features

  • Protected Properties and Methods - Access and override internal functionality in your custom controllers.
  • Lifecycle Hooks - Customize the initialization process at various stages.
  • Modular Service Architecture - Replace or extend individual services for targeted customization.

When to Create Custom Controllers

Consider creating a custom form controller when you need:

  • Specialized validation behaviors
  • Custom analytics integration
  • Industry-specific form behaviors

Creating a Custom Form Controller

To create a custom form controller, extend the FormControllerClass and override specific methods:

custom-controller.ts
1import { FormControllerClass, FormConfig } from '@uplink-protocol/form-controller';
2
3export class CustomFormController extends FormControllerClass {
4 constructor(config: FormConfig) {
5 super(config);
6 // Additional initialization if needed
7 }
8
9 // Override methods as needed
10}

Extension Points

All service instances and state objects are accessible in subclasses:

custom-methods.ts
1class CustomFormController extends FormControllerClass {
2 customMethod() {
3 // Access services directly
4 const fieldData = this.fieldService.getFieldData(stepId, fieldId);
5
6 // Access manager services
7 this.formManagerService.customOperation();
8
9 // Access state
10 const data = this.initialFormData;
11 }
12}

Best Practices

  • Call super methods first

    When overriding methods, call the parent implementation first unless you want to completely replace the behavior.

  • Avoid modifying base services directly

    Instead of modifying the base services, create enhanced services and replace the references in your subclass.

  • Use composition for complex extensions

    For very complex extensions, consider composing multiple controllers rather than deeply nesting inheritance.

  • Document your extensions

    Make sure to document your custom controller's features and how they differ from the base implementation.

Share this page