Skip to content

[Blazor] Form events follow ups #47804

Closed
Closed
@javiercn

Description

@javiercn

For preview 4, forms will bind by providing a name to the event. EditForm sets this event automatically based on the context from the component hierarchy.

We want to make form submission to work with default "form" elements, without having to call an API to define a named event for it.

Potential changes

  • Support binding forms by default. We would special-case "onsubmit" within forms.
    • We would need to check the event name on event handlers to determine that they are onsubmit events. At that point, we would emit the same TrackNamedEvent handler with a default event name.
    • At the time of tracking, we can search the element to see if it defines a name, or id and use that.
    • With that, we get away without having to call SetEventName explicitly.
  • The base renderer just emits calls to track the events, whether explict with SetEventName or "implict" which would only work for submit events in form elements.

How this would work for "plain forms" (without SetEventName)

  • You define the form.
  • You define the "action" attribute.
  • You define the "name" or "id" attribute.

If you have a "name" or "id" attribute, the id attribute takes precedence.

If you define a "name" or "id" attribute, there is a "handler" parameter that needs to appear on the query string for us to be able to route the form.

We will not compute the "action" parameter for you on a default form. If your form has a name, it is your responsibility to figure out the right action value.

How this would work for EditForm.

We will continue to use the existing APIs and generate the name and action attributes for the form based on the CascadingModelBinders in the hierarchy. We can get rid of SetEventName if we want to at that point, but its worth keeping as a perf optimization (it avoid us having to do the look up for the name/id parameters on the element, but at that point, it becomes a "hint")

Metadata

Metadata

Labels

area-blazorIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing one

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions