FluentButton submit does not work outside the EditForm
🐛 Bug Report
In Blazor 8 EditForm, FluentButton submit does not work outside the EditForm, it works fine with normal button.
💻 Repro or Code Sample
@page "/testcomp"
@rendermode InteractiveAuto
<EditForm Model="@_testModel" OnValidSubmit="HandleValidSubmit" id="testform">
<FluentValidationValidator />
<ValidationSummary />
<FluentTextField @bind-Value="_testModel.Name" AriaLabel="Name"></FluentTextField>
</EditForm>
<button type="submit" form="testform">Save</button>
<FluentButton Appearance="Appearance.Accent" IconStart="@(new Icons.Regular.Size16.Save())" Type="Microsoft.FluentUI.AspNetCore.Components.ButtonType.Submit" FormId="testform">Save</FluentButton>
@code {
private TestModel _testModel = new();
private void HandleValidSubmit()
{
Console.WriteLine("Valid");
}
public class TestModel
{
public string? Name { get; set; }
}
public class TestModelValidator : AbstractValidator<TestModel>
{
public TestModelValidator()
{
RuleFor(p => p.Name).NotEmpty().WithMessage("Name required");
}
}
}
🤔 Expected Behavior
Submit should be working fine after setting the FormId.
🌍 Your Environment
- OS & Device: Windows 11
- Browser Microsoft Edge
- .NET 8, FluentUI 4.2.0
Can't see the repo or code sample...
Sorry, copy issue, now updated.
Try it with setting a FormName instead of id
<EditForm Model="@_testModel" OnValidSubmit="HandleValidSubmit" FormName="testform">
Did not work.
And with FluentButton inside from it is OK, I presume?
Why do you want to have it outside form?
Yes, inside the EditForm it works fine.
I am using MudBlazor and Syncfusion for my .Net 7 Project and now I am upgrading to .Net 8 with FluentUI and Syncfusion and removing MudBlazor.
I have lots of forms that are using Syncfution SfDialog, Syncfusion SfDialog Content and Footer is seperate, So I kept form inside Content and Buttons inside Footer.
https://blazor.syncfusion.com/documentation/dialog/template
<SfDialog>
<DialogTemplates>
<Header>
Edit Form
</Header>
<Content>
<EditForm Model="@_testModel" OnValidSubmit="HandleValidSubmit" FormName="testform">
<FluentValidationValidator />
<ValidationSummary />
<FluentTextField @bind-Value="_testModel.Name" AriaLabel="Name"></FluentTextField>
</EditForm>
</Content>
<FooterTemplate>
<FluentButton Appearance="Appearance.Accent" IconStart="@(new Icons.Regular.Size16.Save())" Type="Microsoft.FluentUI.AspNetCore.Components.ButtonType.Submit" FormId="testform">Save</FluentButton>
</FooterTemplate>
</DialogTemplates>
</SfDialog>
So was hoping similar behavior from FluentButton as I am changing to FluentUI components.
Please note that it works with normal button and Syncfusion > SfButton
<EditForm Model="@_testModel" OnValidSubmit="HandleValidSubmit" id="testform">
<FluentValidationValidator />
<ValidationSummary />
<FluentTextField @bind-Value="_testModel.Name" AriaLabel="Name"></FluentTextField>
</EditForm>
<FluentButton Appearance="Appearance.Accent" IconStart="@(new Icons.Regular.Size16.Save())" Type="Microsoft.FluentUI.AspNetCore.Components.ButtonType.Submit" form="testform">Save</FluentButton>
<SfButton IsPrimary="true" type="submit" form="testform">Primary</SfButton>
<button type="submit" form="testform">Save</button>
Ok, found this is a know issue in the underlying scripts (https://github.com/microsoft/fluentui/issues/31506). I implemented a workaround for it which will be in the next release.
For this to start working though, requirement is that you need to supply both Id and FormId parameters to the button:
@page "/IssueTester"
<EditForm Model="@_testModel" OnValidSubmit="HandleValidSubmit" id="testform">
<ValidationSummary />
<FluentTextField @bind-Value="_testModel.Name" AriaLabel="Name" form="testform"></FluentTextField>
</EditForm>
<FluentButton Id="submit" FormId="testform" Appearance="Appearance.Accent" IconStart="@(new Icons.Regular.Size16.Save())" Type="ButtonType.Submit">Save</FluentButton>
<button type="submit" form="testform">Save</button>
@code {
private TestModel _testModel = new();
private void HandleValidSubmit()
{
Console.WriteLine("Valid");
}
public class TestModel
{
public string? Name { get; set; }
}
Hi, was this fixed in V4.3.1?, its still not working.
Yes, the fix is in 4.3.1. Did you see and have you done this:
For this to start working though, requirement is that you need to supply both
IdandFormIdparameters to the button:
(adn the EditForm needs to have an Id set then of course)
oh, thank you. Somehow, I missed reading that part, its working, and i can move forward with FluentUI migration ☺☺☺
Shouldn't this be added to the documentation for the FormId property?
Here's an example that doesn't work. (net8, VS2026.)
@page "/Form"
@rendermode InteractiveServer
@code {
EditForm TheForm { get; set; }
class FormModel
{
public string StringValue { get; set; }
}
FormModel FormValue { get; set; }
protected override void OnParametersSet()
{
FormValue = new FormModel() { StringValue = "string value" };
base.OnParametersSet();
}
void OnValidSubmit()
{
}
}
<Card Class="mb-3">
<CardBody>
<EditForm @ref="@TheForm" FormName="the_form" id="the_form" Model="@FormValue" OnValidSubmit="OnValidSubmit">
<InputText ValueExpression="@(() => FormValue.StringValue)" />
</EditForm>
</CardBody>
</Card>
<button type="submit" form="the_form" class="btn btn-primary">submit from outside form</button>
@rwb196884 what exactly does your code have to do with the library? I don't see any Fluent components in your code...
@vnbaaij it's the same problem; so apparently this is not something to do with Fluent components.
Yes its working if we put Id="create" to the Form then FormId="create" and Id="whatever" to the button, but why we need Id on button?
<FluentStack Orientation="Orientation.Vertical">
<FluentEditForm Model="_data"
OnValidSubmit="Submit"
id="create">
<DataAnnotationsValidator />
<ValidationSummary />
<FluentGrid>
<FluentGridItem xs="12" sm="12" md="6">
<FluentTextField Label="Name"
@bind-Value="data.Name"
Required="true" />
<FluentValidationMessage For="() => data.Name" />
</FluentGridItem>
<FluentGridItem xs="12" sm="12" md="12">
<FluentTextArea Label="Remarks"
@bind-Value="data.Remarks"/>
</FluentGridItem>
</FluentGrid>
</FluentEditForm>
<FluentStack Orientation="Orientation.Horizontal"
HorizontalAlignment="HorizontalAlignment.Left"
Class="pa-2 mt-4">
<FluentButton Appearance="Appearance.Accent"
Type="ButtonType.Submit"
FormId="create"
Id="whatever">
Submit
</FluentButton>
</FluentStack>
</FluentStack>
@anggaputra-ikt thevid is needed to circumvent a limitation of the underlying web component.