Skip to content
Next Next commit
Added the 'FinishAsync' public method.
  • Loading branch information
StevenRasmussen committed Apr 8, 2025
commit d35dce9ab3c554101ec386e07d1f519c033570c2
47 changes: 30 additions & 17 deletions src/Core/Components/Wizard/FluentWizard.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,37 @@ protected virtual async Task<FluentWizardStepChangeEventArgs> OnStepChangeHandle
/// <summary />
protected virtual async Task OnFinishHandlerAsync(MouseEventArgs e)
{
// Validate any form edit contexts
var allEditContextsAreValid = _steps[Value].ValidateEditContexts();
if (!allEditContextsAreValid)
await this.FinishAsync(true);
}

/// <summary>
/// Navigate to the specified step, with or without validate the current EditContexts.
/// </summary>
/// <param name="step">Index number of the step to display</param>
/// <param name="validateEditContexts">Validate the EditContext. Default is false.</param>
/// <returns></returns>
public Task GoToStepAsync(int step, bool validateEditContexts = false)
{
return ValidateAndGoToStepAsync(step, validateEditContexts);
}

/// <summary>
/// Optionally validate and invoke the <see cref="OnFinish"/> handler.
/// </summary>
/// <param name="validateEditContexts">Validate the EditContext. Default is false.</param>
/// <returns></returns>
public async Task FinishAsync(bool validateEditContexts = false)
{
if (validateEditContexts)
{
// Invoke the 'OnInvalidSubmit' handlers for the edit forms.
await _steps[Value].InvokeOnInValidSubmitForEditFormsAsync();
return;
// Validate any form edit contexts
var allEditContextsAreValid = _steps[Value].ValidateEditContexts();
if (!allEditContextsAreValid)
{
// Invoke the 'OnInvalidSubmit' handlers for the edit forms.
await _steps[Value].InvokeOnInValidSubmitForEditFormsAsync();
return;
}
}

// Invoke the 'OnValidSubmit' handlers for the edit forms.
Expand All @@ -255,17 +279,6 @@ protected virtual async Task OnFinishHandlerAsync(MouseEventArgs e)
}
}

/// <summary>
/// Navigate to the specified step, with or without validate the current EditContexts.
/// </summary>
/// <param name="step">Index number of the step to display</param>
/// <param name="validateEditContexts">Validate the EditContext. Default is false.</param>
/// <returns></returns>
public Task GoToStepAsync(int step, bool validateEditContexts = false)
{
return ValidateAndGoToStepAsync(step, validateEditContexts);
}

internal async Task ValidateAndGoToStepAsync(int targetIndex, bool validateEditContexts)
{
var stepChangeArgs = await OnStepChangeHandlerAsync(targetIndex, validateEditContexts);
Expand Down