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.

Static Access to Validation Error Strings

See original GitHub issue

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

forms

Description

We can retrieve the boolean value for a specific Validator like this:

this.email.hasError('email')

I would be nice if we could get programmatic access to the correct email string like this:

this.email.hasError(Validators.EMAIL_KEY)

Proposed solution

this.email.hasError('Validators.EMAIL_KEY')

Alternatives considered

Just type the string … email

The thing is … if we make a mistake … for example typing minLength … instead of minlength

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
fireflysemanticscommented, Jan 26, 2022

@Totati IIUC control.hasValidator checks whether the control has a specific validator.

So for example:

this.email.hasValidator(Validators.email)

Will return true if the email control has the Validators.email validator assigned to it.

This is different from:

this.email.hasError(Validators.EMAIL_KEY)

Which checks whether the errors property on the control has a specific keyed error. In this case that error would be triggered if the value of the email control is not a valid email address …

0reactions
angular-automatic-lock-bot[bot]commented, Jul 14, 2022

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Share data between static method and static event handler
My problem is, the static validation method needs to return a bool flag to indicate if there were any errors, and an output...
Read more >
validation - 1.2.7 - Play Framework
Validation error messages. At the end of the validation you can check if any errors have been created and display them: public static...
Read more >
c# How to perform multiple validation and return error ... - MSDN
So, just add an array with the error messages ( for the equivalent indexes ), and iterate through the array using the static...
Read more >
Validation and Error Messages - Elastic Path Documentation
When a user takes an action that violates a business state or provides invalid input, an error is generated in Commerce Engine.
Read more >
Handling validation messages in Angular like a boss
Tired of writing validation messages for each control and applying conditions to show them? In this post, I will explain how to create...
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