Skip to content

Commit 83880f7

Browse files
javiercngithub-actions
authored andcommitted
Update EditContextModelBindingContextExtensions.cs to only call NotifyValidationStateChanged on Dispose, if there were registered messages
1 parent c2e3f46 commit 83880f7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Components/Web/src/Forms/EditContextModelBindingContextExtensions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ private sealed class BindingContextEventSubscriptions : IDisposable
5252
private readonly EditContext _editContext;
5353
private readonly ModelBindingContext _bindingContext;
5454
private ValidationMessageStore? _messages;
55+
private bool _hasmessages;
5556

5657
public BindingContextEventSubscriptions(EditContext editContext, ModelBindingContext serviceProvider)
5758
{
@@ -85,6 +86,7 @@ private void OnValidationRequested(object? sender, ValidationRequestedEventArgs
8586
adddedMessages = true;
8687
// TODO: We need to support localizing the error message.
8788
_messages.Add(fieldIdentifier, errorMessage.ToString(CultureInfo.CurrentCulture));
89+
_hasmessages = true;
8890
}
8991
}
9092

@@ -99,7 +101,10 @@ public void Dispose()
99101
{
100102
_messages?.Clear();
101103
_editContext.OnValidationRequested -= OnValidationRequested;
102-
_editContext.NotifyValidationStateChanged();
104+
if (_hasmessages)
105+
{
106+
_editContext.NotifyValidationStateChanged();
107+
}
103108
}
104109
}
105110
}

0 commit comments

Comments
 (0)