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.
In this example a basic input control is registered.
Step 1 - Create component
Copy @ 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 ;
}
Copy < mat-form-field >
< mat-label *ngIf = "question.label" >{{question.label}}</ mat-label >
< input #inputElement [formControl] = "control" [type] = "type" matInput />
< mat-icon *ngIf = "format === 'currency'" matSuffix >€</ mat-icon >
< mat-error *ngIf = "control.hasError('required')" > Value is required </ mat-error >
</ mat-form-field >
Copy FastFormsModule .forRoot ({
controls : [InputComponent] ,
});
Copy FastFormsModule .forChild ({
controls : [InputComponent] ,
});