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.

Have an access to 'formControlName' value inside a custom validation function

See original GitHub issue

I’m submitting a … (check one with “x”)

[ ] bug report
[x] feature request
[ ] support request

Current behavior There is no way how to get the value of ‘formControlName’ inside a custom validation function to identify which control is beeing actually validated (model-driven forms) because the only parameter is (c: FormControl) and the actual API of ‘FormControl’ is:

_errors, _onChange, _parent, _pristine, _status, _statusChanges, _touched,
_value, _valueChanges, asyncValidator, dirty, errors, pending, pristine,
root, status, statusChanges, touched, untouched, valid, validator, value, valueChanges

Expected/desired behavior Be able to get ‘formControlName’ value inside a custom validation and generic function and use it as the identity of the actually validated control. It allows to have a dynamic set of validation rules for each control (for example in JSON syntax) that could be maintenated outside of the app code then.

What is the motivation / use case for changing the behavior? To be more flexible and minimize the code = reducing the number of custom validators.

Please tell us about your environment:

  • Angular version: 2.0.0-rc.4
  • Browser: [all]
  • Language: [all]

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mlc-mlapiscommented, Oct 12, 2016

@kara Thanks for info. I understand that my previous problem description was not enough. I still think that there are real cases (including our projects) where our vision will be beneficial.

I will return to this thema and open a new issue when I have enough free time to collect descriptions that would be good enough to explain and convince.

1reaction
mlc-mlapiscommented, Aug 10, 2016

Of course I know but still the main problem remains and there is no solutions except many and many lines of code. So that is why a feature request was created because it is evident that a validator should know on which control he is running.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Use Custom Form Validation in Angular - DigitalOcean
Learn how to create a custom validator in Angular for both template-driven and reactive forms.
Read more >
How to pass Form Group control value to a Custom Validator ...
The function get the password field and compare with confirm password ... And you can directly pass the value of password from group...
Read more >
Angular Custom Form Controls - Complete Guide
In this guide, we are going to learn exactly how to take an existing custom form control component and make it fully compatible...
Read more >
Custom Form Validators • Angular - codecraft.tv
A validator in Angular is a function which returns null if a control is valid or an error object if it's invalid. For...
Read more >
Validating form input - Angular
The built-in validators don't always match the exact use case of your application, so you sometimes need to create a custom validator. Consider...
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