A reopened calendar form shows required errors before any in


Topic: A reopened calendar form shows required errors before any input

foxgrid_dev pro asked a week ago

Our custom appointment dialog uses a reactive form. After submitting an empty form, required-field messages appear as expected. If I close the dialog and reopen it to create another appointment, the blank fields immediately show the same errors.

The component stays mounted between openings. We clear the values with patchValue, and the template displays errors when a control is invalid and touched. What else should be reset when starting a new appointment?


patchValue changes values without resetting the interaction state. Use the form's reset method with the initial values when starting a new appointment. This returns the controls to pristine and untouched as well as clearing the previous values.

If the template also uses your own submitted flag, reset that flag at the same time. If it uses FormGroupDirective.submitted, reset the form directive too. Keep the invalid-and-touched condition so that a genuinely edited empty field still receives feedback.

startNewAppointment() {
  this.submitted = false;
  this.form.reset({ title: '', location: '', notes: '' });
}

https://mdbootstrap.com/docs/angular/plugins/calendar/


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue
  • User: Pro
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: MDB5 9.1.0
  • Device: Desktop
  • Browser: Edge
  • OS: Windows 11
  • Provided sample code: No
  • Provided link: No