Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HxInputDateRange] Using FluentValidationValidator to require non null value for HxDateTimeRange tries to create 2 spans with the same key. #676

Closed
JoseTheChamp opened this issue Nov 28, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@JoseTheChamp
Copy link
Contributor

I have following code:

public class TimesheetsReportFilterModelValidator : AbstractValidator<TimesheetsReportFilterModel>
{
	public TimesheetsReportFilterModelValidator(Reports.Resources.ITimesheetsReportsFilterLocalizer timesheetsReportsFilterLocalizer)
	{
		RuleFor(m => m.Period).Must(period => period.StartDate.HasValue).When(m => m.PeriodStartRequired).WithMessage(timesheetsReportsFilterLocalizer.PeriodStartRequired);
		RuleFor(m => m.Period).Must(period => period.EndDate.HasValue).When(m => m.PeriodEndRequired).WithMessage(timesheetsReportsFilterLocalizer.PeriodEndRequired);
	}
}

Where property "Period" is of type DateTimeRange. Then i use this property and bind it to a HxDateTimeRange:
<HxInputDateRange InputSize="InputSize.Small" Label="@TimesheetsReportsFilterLocalizer.Period" @bind-Value="_model.Period" />
I then on initialization fill up these two fields, but when i clear one of those, then following error is thrown:

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: More than one sibling of element 'span' has the same key value, 'Enter start date.'. Key values must be unique.
System.InvalidOperationException: More than one sibling of element 'span' has the same key value, 'Enter start date.'. Key values must be unique.
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ThrowExceptionForDuplicateKey(Object key, RenderTreeFrame& frame)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.BuildKeyToInfoLookup(DiffContext diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer renderer, RenderBatchBuilder batchBuilder, Int32 componentId, ArrayRange`1 oldTree, ArrayRange`1 newTree)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()

Note that the "Enter start date" in:

More than one sibling of element 'span' has the same key value, 'Enter start date.'

is the message passed to the AbstractValidator in WithMessage() method.

A potential solution to this problem could be for this component to implement its own null checking based on some parameter.

@hakenr hakenr self-assigned this Nov 28, 2023
@hakenr hakenr added the bug Something isn't working label Nov 28, 2023
@hakenr hakenr changed the title Using FluentValidationValidator to require non null value for HxDateTimeRange tries to create 2 spans with the same key. [HxInputDateRange] Using FluentValidationValidator to require non null value for HxDateTimeRange tries to create 2 spans with the same key. Dec 4, 2023
@hakenr hakenr added this to the Priority 1 - High milestone Dec 4, 2023
hakenr added a commit that referenced this issue Dec 7, 2023
…n null value for HxDateTimeRange tries to create 2 spans with the same key.
@hakenr
Copy link
Member

hakenr commented Dec 7, 2023

@hakenr
Copy link
Member

hakenr commented Dec 12, 2023

The InvalidOperationException during HxValidationMessage rendering was "fixed" in v4.3.5. It no longer fails on duplicate validation messages. It is out of scope of this issue where do the duplicate validation messages come from.

@hakenr hakenr closed this as completed Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants