Skip to content

Main EditContext validates successfully although custom ValidationMessageStore associated to scoped EditContext indicates otherwise #5

@teneko

Description

@teneko

When someone is using a custom ValidationMessageStore in a scoped EditContext then the main EditContext won't know about it.

<EditForm Model="_model">
  <EditModelScope>
    <CustomControlWithOwnValidationMessageStore />
  </EditModelScope>
<EditForm>

Proposal

The only way to solve it is to create a custom Dictionary beside its default behaviour and monkey patch the dictionary in every scoped EditContext. On every addition of a new FieldState we must also monkey monkey its HashSet that bubbles up the validation message store registration to the root EditContext. We also must monkey patch the HashSet of ValidationMessageStore. We can do that safely, because a ValidationMessageStore has a 1:1 relationship to a specific EditContext.

The only way to get some live hooks is using a IEqualityComparer for Dictionary keys and the HashSet values and react on calls calls of GetHashCode. We must implement the following primitives:

  • To detect the first user-driven GetHashCode of any IEqualityComparer we must always place a warmup entry.
  • To detect a ValidationMessageStore addition, we must check in FieldState if _message entry is already existing.
  • To detect a ValidationMessageStore removal we must check in ValidationMessageStore if the FieldState entry is already gone.
  • To detect a ValidationMessageStore clear we must look for removal of warmup entry of ValidationMessageStore in FieldState.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions