Form Control

To add a form control you have to create a new angular component via the angular CLI or manually. It must be annotated with @Control and a type must be given. See the following example for more information.

Example

In this example a basic input control is registered.

Step 1 - Create component

@Control({
  type: 'my-input',
})
@Component({
  selector: 'custom-input',
  templateUrl: './input.component.html',
})
export class InputComponent {
  
  constructor(
    @Inject(FORM_CONTROL) public control: FormControl,
    public question: QuestionDefinition,
    @Inject(CONTROL_PROPERTIES) private properties: InputProperties
  ) {}

  public get type(): string {
    switch (this.format) {
      case 'text':
        return 'text';
      case 'number':
        return 'number';
      case 'currency':
        return 'number';
      default:
        return 'text';
    }
  }

  public get format(): InputFormat {
    return this.properties.format ?? 'text';
  }
}

interface InputProperties {
  format?: InputFormat;
}

Step 2 - Registration

The custom control component must be registered in the FastFormsModule. See the following example.

Root Module

Child Module

Last updated