Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to reset angular form and set default values after submitting

My expected results is to reset the form after it has been submit and set its default values binded to the formGroup control. I am attempt to reset the form to its default data after submitting by calling reset() on the form submit. Please advise me on how can I reset the default value in the date and time field .

Example :

pickupDate = new Date().toISOString().slice(0,10);
pickupTime = moment().format() ;

onSubmit(orderData: Order){
        this.apiService(orderData).subscribe( order => {
                 orderForm.reset()
})
}

Please help Thanks

like image 404
d-shall Avatar asked Dec 08 '22 15:12

d-shall


1 Answers

After submitting your form. you are calling

this.yourForm.reset()

Then you can patch initial values to the form like this.

this.yourForm.patchValue({
  firstControllerName: this.initialValues.value1,
  secondControllerName: this.initialValues.value2,
  // other controller names goes here
});

Hope this helps.

like image 147
Anuradha Gunasekara Avatar answered Dec 28 '22 06:12

Anuradha Gunasekara