question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why don't reactive forms have a 'message' field directed to each validator's messages?

See original GitHub issue

Which @angular/* package(s) are relevant/releated to the feature request?

No response

Description

It would be very useful if the reactive forms had the possibility to add messages for each validator. This would make it easier to change the text of messages when needed.

Proposed solution

TS:

this.form = this.fb.group({
    name: [
      '',
      [
        Validators.required({ message: 'Field required' }),
        Validators.minLength({ lenght: 15, message: 'Min. length: {0}' }),
      ],
    ],
  });

HTML:

<label *ngIf="this.form.get('name').hasError('required') && this.form.get('name').touched">
  {{this.form.get('name').errors.get('required').message}}
</label>

Alternatives considered

Something similar to flutter’s reactive forms:

image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:37
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
AndrewKushnircommented, Jun 21, 2022

Hi @CarvalhoWesley, thanks for creating this feature request. We’ll discuss it during one of the upcoming team syncs and provide an update on whether we decide to move forward with this feature or not. Thank you.

1reaction
angular-robot[bot]commented, Sep 11, 2021

This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we’ll move it to our consideration list.

You can find more details about the feature request process in our documentation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Display Validation or Error Messages in Angular Forms
This guide covers how to display validation or error messages with Angular forms. It looks at both template-driven forms and reactive forms.
Read more >
Show Validation Error Messages for Reactive Forms in ...
In this example, I'll define a reactive form with one text field. We'll configure this field to have a few validation rules before...
Read more >
Angular Reactive Forms Validation Messages Not Showing
Validations are correctly running. (When type in valid email, form field become red) But validation message not shown.It was perfecty work ...
Read more >
Angular Forms and Validations
Reactive Forms, Template-driven Forms. Setup of form model, Explicit, created in component class, Implicit, created by directives.
Read more >
Working with Angular 4 Forms: Nesting and Input Validation
Validating user inputs is an essential part of any robust web application. Angular 4 makes it especially easy for both template-driven and reactive...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found