-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Unclear error message for badly configured custom form controls #44486
Comments
Hi @mwaibel-go, the mentioned error was caused by the missing
which makes it a regular provider (vs a multi provider that the code expects). Here is the code location: angular/packages/forms/src/directives/shared.ts Lines 317 to 318 in 8ebc946
I think we can improve the error message by including a note like this:
I think there might also be an opportunity to improve the logic around getting the attribute name (so that there is a real name vs "unspecified attribute"). Could you please create a simple example of your structure using Stackblitz, so that we can look at the logic that calculates the name and see if there is a way to improve it? |
Thank you for responding. Yes, I can certainly provide a repro. It might take until the weekend, though. Sorry for replying so late. I did not get a notification for your response. |
Here is a reproduction from my alt account: https://stackblitz.com/edit/angular-ivy-e2wj4z?file=src/app/app.component.ts |
@AndrewKushnir Can I work on this issue? |
@ameryousuf sure, please let me know if you have any questions. Thank you. |
@AndrewKushnir I changed the error message as you suggested, and opened the PR. However, regarding improving the logic around getting the attribute name (so that there is a real name vs "unspecified attribute"), do you have any idea how to improve it? Since the Besides, we can't move the call of the |
@ameryousuf thanks for creating the PR and sorry for the delay in answering. If I understand correctly, the problem happens with the
My proposal is to proceed with PR #45192 without this change and create a followup PR (which would also require some tests). Please let me know if any additional information is needed. Thank you. |
@AndrewKushnir Thanks for your reply. Actually, it's related to the Why? Because the So, your suggestion won't work in this case. We can resolve it by calling the ngOnChanges(changes: SimpleChanges): void {
if (!this.valueAccessor) {
// Initializing the `valueAccessor` here, gives as the opportunity to access the @Input('name') value from the `selectValueAccessor` function.
this.valueAccessor = selectValueAccessor(this, this.valueAccessors);
}
// ....
} I tested the above change and it didn't break any unit tests. Regarding the What do you suggest, please? |
@ameryousuf thanks for the comment. You are right, the inputs wouldn't be available until the first |
Okay, thanks @AndrewKushnir. Please let me know if you need any help in the future. Thanks! |
Dear @dylhunn and @AndrewKushnir, I was looking at the "good first issue" list and I found this issue. I'd like to contribute, but first I wanted to check with you. I see a PR 45192 which was closed for inactivity, should I take it as a base? What would you suggest to the beginner? :) |
looks like the pr is already closed after committing the changes, maybe the issue is still open because of the second problem that is yet to be addressed which is this |
Sorry about the confusion. I think the error message was improved in #45192, so we can close this ticket. Thank you. |
thank you for the quick response |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Which @angular/* package(s) are relevant/releated to the feature request?
forms
Description
I was hitting the following error when implementing a custom form control:
It was very unclear to me what this error message meant or how to fix it. My form controls all had names and formControlNames.
Only by uncommenting parts of my form could I even find the offending form control, since the error doesn’t specify what it was trying to do when the error occured.
Googling the error only brought up the source code for the test regarding this error, but there’s no explanation why an error is thrown there, either.
The actual error was that my form control was badly configured, i.e. it provided the NG_VALUE_ACCESSOR like this:
instead of this
Maybe related? Maybe related: #3011
Here’s a reproduction: https://stackblitz.com/edit/angular-ivy-e2wj4z?file=src/app/app.component.ts
Proposed solution
Since I still don’t know the actual cause of the error, I can’t propose a solution to a clearer error message. It would be nice to know the class or form control something was trying to process when the error happens.
Andrew Kushnir proposed a solution:
Alternatives considered
—
The text was updated successfully, but these errors were encountered: