-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ng-core] Provide validators #76
Comments
Hey cool! Thank you for the PR. It looks like this tackles one piece of #41. Looking at the sample code Dmitry wrote for that issue, I see you took different approaches. Or, actually, it looks like Dmitry was concerned with validation errors that are set on the wrapper control and propagates them to the inner control, whereas you go the opposite direction. Maybe it's time for me to roll up my sleeves and get back to this! (There was an Angular issue that prevented it the last couple times I tried, but I think it has finally been resolved.) |
@DmitryEfimenko I've come back around to thinking about synchronizing things between outer and inner form controls again. 🙂 @KrickRay and @DmitryEfimenko can you think of any examples when users would NOT want validation to be synchronized from outer to inner controls, or inner to outer? I.e. can you think of a reason a user would need to turn synchronization OFF?
|
I'm not sure what you mean in the first example (Outer -> Inner) when you say "so the outer user needs to opt in". Opt in to synchronize validation? But I thought that it's syncronized by default |
Outer -> Inner With external errors, I see problems:
Inner -> Outer If the developer decides to do internal validation, then it must be mandatory and cannot be disabled. The library only allows you to add it If he wants to make it optional, then he has two options:
|
@DmitryEfimenko By "opt in" I mean the user must be able to choose whether or not the component is required depending on the situation. The user must have the ability to opt in to that validation, rather than having it unconditionally required everywhere. I'm evaluating whether it should be always synchronized, optionally synchronized, or never synchronized in each direction. @KrickRay I'm not fully following, I'm sorry to say. Do you have example use cases in mind? (Or can you make up plausible ones?) |
For the option I proposed (inner->outer), and so it will be optional for the developer and he will be able to decide. The last update was difficult, the library changed naming, and if more new behavior is added, this will add new difficulties. Better if the new behavior is optional.
About examples, I personally need the inner->outer to get validation from nested |
I remember why I wanted to sync outer to inner. The only use-case I had for it was to style inputs as invalid. I didn't care what exact error the outer control had - just needed the red outline on the inner inputs that you get automatically due to the I didn't come across a use case where I needed to come up with a solution to custom sync inner to outer errors. What I mean is that providing standard |
I definitely see the usefulness of synchronization both ways. Thank you for the examples. I can use |
Ah yes, it's coming back to me. You pointed me to the video before. Thank you. After playing around a while I think I have the right solution figured out: Inject Inner->outer only makes sense when there is an outer Does that sound right to you guys? |
Ah - sorry for the spam. I already realized that doesn't handle reactive forms where the user manually adds validators to the outer control. New proposal: sync both directions with That covers all the scenarios I can think of except when something other than NgControl wants to know about inner validation errors. Maybe there is another custom directive the user adds to the component that tries to inject |
… errors with its outer `NgControl`, if one exists BREAKING CHANGE: Errors from validation outside and inside a `WrappedControlSuperclass` are now synchronized both ways. See the docs for examples to modify or disable this process. Closes #76
Support is coming with version 14. See the commit that Github auto-linked above. Feel free to look it over and offer any early feedback if desired! |
I just released
|
Published. |
I suggest adding internal validation. Sometimes custom controls need to validate something by default, such as mail, card data, and other business entities.
I did a basic PR, but I didn't find any installation information to run and write tests.
The text was updated successfully, but these errors were encountered: