ngx-custom-validators icon indicating copy to clipboard operation
ngx-custom-validators copied to clipboard

[Feature Request] notEqualTo should include name of control

Open lonix1 opened this issue 6 years ago • 2 comments
trafficstars

Similar to #12

Let's say we define a "password" validation like this:

password: ["", [Validators.required, CustomValidators.notEqualTo(email)]],

The notEqualTo validator's metadata includes the invalid value, so we can show this message:

'password' cannot equal '[email protected]'

But, this is not informative. It should include the name of the target control (email), so that we can do this instead:

'password' cannot equal 'email'

That makes more sense.

So passwordControl.errors should return: { control: {}, otherControlName: 'email' }

lonix1 avatar Jun 12 '19 17:06 lonix1

What's the goal?

To use the control name with a translation and display it to the user?

rsaenen avatar Jun 13 '19 08:06 rsaenen

Yes, so you can use this:

'password' cannot equal 'email'

Otherwise you don't know which control (i.e. email) it equalled.

lonix1 avatar Jun 13 '19 09:06 lonix1