Skip to content

Commit

Permalink
Fix validation when @bind-Value is set for FluentWizard component (#2364
Browse files Browse the repository at this point in the history
)

* Fixing issue where FluentWizard stops validating when @bind-Value is set

fix: validation stops working when @bind-Value is set on the FluentWizard component to an integer property on the page

Adding test to validate that index does not change on next within wizard component

* Making recommended changes

---------

Co-authored-by: ErikJohnsonLRS <[email protected]>
Co-authored-by: Denis Voituron <[email protected]>
  • Loading branch information
3 people authored Jul 16, 2024
1 parent 21981af commit f8998c7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/Core/Components/Wizard/FluentWizard.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ protected virtual async Task OnNextHandlerAsync(MouseEventArgs e)
if (!isCanceled)
{
Value = targetIndex;
await ValueChanged.InvokeAsync(targetIndex);
StateHasChanged();
}
}
Expand All @@ -183,14 +184,16 @@ protected virtual async Task OnPreviousHandlerAsync(MouseEventArgs e)
if (!isCanceled)
{
Value = targetIndex;
await ValueChanged.InvokeAsync(targetIndex);
StateHasChanged();
}
}

/// <summary />
protected virtual async Task<FluentWizardStepChangeEventArgs> OnStepChangeHandlerAsync(int targetIndex, bool validateEditContexts)
{
var stepChangeArgs = new FluentWizardStepChangeEventArgs(targetIndex, _steps[targetIndex].Label);
var stepChangeArgs = new FluentWizardStepChangeEventArgs(targetIndex, _steps[targetIndex].Label);

if (validateEditContexts)
{
var allEditContextsAreValid = _steps[Value].ValidateEditContexts();
Expand All @@ -209,8 +212,6 @@ protected virtual async Task<FluentWizardStepChangeEventArgs> OnStepChangeHandle
await _steps[Value].InvokeOnSubmitForEditFormsAsync();
}

await ValueChanged.InvokeAsync(targetIndex);

return await OnStepChangeHandlerAsync(stepChangeArgs);
}

Expand Down Expand Up @@ -269,6 +270,7 @@ internal async Task ValidateAndGoToStepAsync(int targetIndex, bool validateEditC
if (!isCanceled)
{
Value = targetIndex;
await ValueChanged.InvokeAsync(targetIndex);
StateHasChanged();
}
}
Expand Down
5 changes: 4 additions & 1 deletion tests/Core/Wizard/FluentWizardTests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@
[Fact]
public void FluentWizard_EditForm_EditContextIsInValid_OnNext()
{
int stepIndex = 0;

var testRecord1 = new TestRecord
{
NumberBetween1and10 = 15,
Expand All @@ -333,7 +335,7 @@
NumberBetween1and10 = 15,
};

var cut = Render(@<FluentWizard OnFinish="OnFinishHandler">
var cut = Render(@<FluentWizard OnFinish="OnFinishHandler" @bind-Value="@stepIndex">
<Steps>
<FluentWizardStep>
<FluentEditForm Model="testRecord1">
Expand Down Expand Up @@ -370,6 +372,7 @@
}

Assert.False(finishHandled);
Assert.Equal(0, stepIndex);
}

[Fact]
Expand Down

0 comments on commit f8998c7

Please sign in to comment.