I am using blazor SFDataForm in SFDialog component.
I need to submit the form using a DialogButton which is not FormButton as you guess.
For this I am using EditContext of the form, validating it in button click event
But in this case FormValidator does not get triggered.
Though I am able to validate the form.
<SfDataForm ID="rollForm"
@ref="dataForm"
Model="@RollData"
ColumnCount=1
ColumnSpacing="10px"
LabelPosition="FormLabelPosition.Top"
EditContext="@editContext">
<FormValidator>
<DataAnnotationsValidator></DataAnnotationsValidator>
</FormValidator>
<FormItems>
...
...
</FormItems>
<FormButtons>
<!-- I don't want to use form buttons-->
</FormButtons>
</SfDataForm>
...
<DialogButtons>
<DialogButton Content="Save" CssClass="e-success" OnClick="@OnSave" IsFlat="false />
...
....
</DialogButtons>
</SfDialog>
@code {
...
public RollDataDTO? RollData { get; set; }
private EditContext? editContext { get; set; }
...
protected override Task OnInitializedAsync()
{
editContext = new EditContext(new RollDataDTO());
return base.OnInitializedAsync();
}
private async Task OnSave()
{
var valid = editContext.Validate();
if (valid)
{
await OnSaveCallback.InvokeAsync(RollData);
this.IsVisible = false;
}
else
{
Console.WriteLine("Form validation failed.");
}
}
}