Open Closed

How can I force show validation errors in an angular UI? #1806


User avatar
0
GregB created
  • ABP Framework version: v4.3.3
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace: N/A
  • Steps to reproduce the issue:"

How can I force all validation errors to show in an Angular form?

I've got a simple form with a required field

 this.form = this.fb.group({
            name: [name ?? null, [Validators.required]]
           });

But when I click submit, no errors are shown.

submitForm()
{
   if(!this.form.valid)
   {
       // How do I show the errors?
       return;
   }
   
   // ...
}

If I type something into the field, then delete it, the required validation message shows.

I want to show all validation errors when the user tries to submit an invalid form.

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

1 Answer(s)
  • User Avatar
    1
    Mehmet created

    Hello @GregB

    There are two ways to achieve this:

    • You should mark form controls as dirty as shown below:
    if(!this.form.valid)
    {
       Object.values(this.form.controls).forEach((control) => {
            control.markAsDirty();
            control.updateValueAndValidity();
        });
       return;
    }
    
    • You can use the ngx-validate's valiteOnSubmit directive. See the working example: https://stackblitz.com/edit/ngx-validate?file=src/app/components/app.component.html
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 28, 2026, 11:44
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.