form: FormGroup;
createMyForm() {
this.form = new FormGroup<any>({
firstName: new FormControl<any>('', [Validators.required]),
lastName: new FormControl<any>('', { nonNullable: true }),
});
}
How to add { nonNullable: true } to firstName
I am trying to add {nonNullable: true } to the form control.
lastName: new FormControl('', { nonNullable: true }),
I am able to add {nonNullable: true } to the control which doesnt have validations, but for the form control which has validations I am not able to add {nonNullable: true }.
firstName: new FormControl('', [Validators.required]),
createMyForm() {
this.form = new FormGroup<any>({
firstName: new FormControl<any>('', {
nonNullable: true,
validators: [Validators.required]
}),
lastName: new FormControl<any>('', { nonNullable: true })
});
}
if all fields has nonNullable:true
and you are comfortable injecting form-builder, you can use NonNullableFormBuilder
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With