-
Notifications
You must be signed in to change notification settings - Fork 199
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
Fix warning for @formname
without @onsubmit
#9296
Conversation
Could you clarify why there even is a warning/error for If interpreted with no other context, it's not true - you can have either In all cases, |
Ah, OK, I thought it's not allowed, probably looking at the runtime implementation: I will remove the warning completely then.
Even if allowing |
Understood. There is a misleading comment left behind there. Fortunately we do have E2E test cases that exercise
Yes, that's fine. Thanks for checking! There is currently no use case for |
{ | ||
return RazorDiagnostic.Create(FormName_MissingOnSubmit, source ?? SourceSpan.Undefined); | ||
} | ||
// Removed warning RZ10021: Attribute '@formname' can only be used when '@onsubmit' event handler is also present. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think we can delet this comment
// Act | ||
var generated = CompileToCSharp(""" | ||
<form method="post" @onsubmit="() => { }" @formname="named-form-handler"></form> | ||
<form method="post" @onsubmit="() => { }" @formname="@("named-form-handler")"></form> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this test it appears no code is really generated and no diagnostics are emitted. Is that correct? If so it seems a bit odd to me that we do nothing and don't alert the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The @formname
is translated into AddNamedEvent
normally - https://github.com/dotnet/razor/blob/f808c223fdbdbc2a05069005c9693022d4cc693e/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/FormName_MissingUsing/TestComponent.codegen.cs. The @onsubmit
is emitted as-is but that's a pre-existing behavior - all events behave like this when the event handler is not registered.
Could perhaps implement a warning for this specific scenario - like "you seem to be using @formname
with broken @onsubmit
, did you mean to have event handler for @onsubmit
registered?" - but that's something that shouldn't happen to users normally and if we want to do that, I guess it could be a follow up PR.
Related to #9077.
Discovered when updating SDK in ASP.NET Core repo: dotnet/aspnetcore#50734
This removes warning
RZ10021: Attribute '@formname' can only be used when '@onsubmit' event handler is also present.
which was reported in wrong cases (even if user had valid@onsubmit
) plus it became clear that it's not needed at all (@formname
should be allowed without@onsubmit
).(The warning condition was wrong because the integration tests didn't register/process the event like real ASP.NET Core setting would - I fixed that in this PR for the
@formname
tests by adding@using Microsoft.AspNetCore.Components.Web
.)