Skip to content
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

Add Razor compiler support for the @formname attribute #9077

Closed
MackinnonBuck opened this issue Aug 2, 2023 · 2 comments · Fixed by #9153
Closed

Add Razor compiler support for the @formname attribute #9077

MackinnonBuck opened this issue Aug 2, 2023 · 2 comments · Fixed by #9153
Assignees
Labels
area-blazor area-compiler Umbrella for all compiler issues
Milestone

Comments

@MackinnonBuck
Copy link
Member

MackinnonBuck commented Aug 2, 2023

Blazor will support a new @formname attribute for use on <form> elements. For example:

<form method="post" @onsubmit="() => _submitted = true" @formname="named-form-handler">
    <AntiforgeryToken />
    <InputText @bind-Value="Parameter" />
    <input id="send" type="submit" value="Send" />
</form>

@if (_submitted)
{
    <p id="pass">Hello @Parameter!</p>
}

@code{
    bool _submitted = false;

    [SupplyParameterFromForm(Handler = "named-form-handler")] public string Parameter { get; set; } = "";
}

This is currently handled in Blazor by doing a special check for the @formname attribute name in RenderTreeBuilder.AddAttribute, but we want this to be handled by the Razor compiler instead.

When encountering @formname="named-form-handler", the Razor compiler should output:

__builder.AddNamedEvent("onsubmit", "named-form-handler");
@chsienki
Copy link
Contributor

@jjonescz Feel free to take this one, we might need to do a bit of Language Design but I think most of it is ready to go.

@SteveSandersonMS
Copy link
Member

Note that as per https://github.com/dotnet/Razor-Language-Design/discussions/3#discussioncomment-6719692, we removed the sequence parameter from AddNamedEvent. I've also updated the spec above to match.

@chsienki chsienki modified the milestones: 17.8 Planning, 17.8 P2 Aug 25, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Oct 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor area-compiler Umbrella for all compiler issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants