0
votes

I have been using reactive forms since a while but, right now i am facing a issue while resetting it. My aim is inline CRUD operations to a table of records.

Create Form:

formGroupName.formBuilder.group({
    fieldName: '',
    fieldName1: ''
}, { validator: CustomValidator });

Form Reset:

formGroupName.reset({
    fieldName: ['', Validators.required],
    fieldName1: ['', Validators.required]
});

While adding a record, i display a form to the top of the table and i also perform a this.formGroupName.reset() function. And afterwards i reset it and i click the add button form gets reset and CustomValidator doesn't work at all whereas the other validators(required) do work fine. I have tried the same thing by replacing reset with patch value.

Custom validators do work when i write the code for creating the form again after the reset function which i feel is not the right solution as it makes me to write the same code again before and after calling the reset function.

Please advise.

1

1 Answers

0
votes

on FormReset try this. worked for me

formGroupName.reset({
    fieldName: ('',[ Validators.required, CustomerVaidator]),
    fieldName1: ('',[ Validators.required, CustomerVaidator])
});