Skip to content

Commit 0967a71

Browse files
committed
Fix BindableReactiveProperty validation
1 parent e47c5b7 commit 0967a71

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/R3/BindableReactiveProperty.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,24 @@ protected override void OnValueChanged(T value)
7979
{
8080
if (enableNotifyError)
8181
{
82+
// comes new value, require to clear error.
83+
var previouslyHasErrors = (errors != null && errors.Count != 0);
84+
errors?.Clear();
85+
8286
if (validationContext != null)
8387
{
8488
if (errors == null)
8589
{
8690
errors = new List<ValidationResult>(validationContext.ValidatorCount);
8791
}
88-
errors.Clear();
8992

9093
if (!validationContext.TryValidateValue(value, errors))
9194
{
9295
ErrorsChanged?.Invoke(this, ValueChangedEventArgs.DataErrorsChanged);
93-
94-
// set is completed(validation does not call before set) so continue call PropertyChanged
96+
}
97+
else if (previouslyHasErrors)
98+
{
99+
ErrorsChanged?.Invoke(this, ValueChangedEventArgs.DataErrorsChanged);
95100
}
96101
}
97102
else if (validator != null)
@@ -101,13 +106,16 @@ protected override void OnValueChanged(T value)
101106
{
102107
OnReceiveError(error);
103108
}
109+
else if (previouslyHasErrors)
110+
{
111+
ErrorsChanged?.Invoke(this, ValueChangedEventArgs.DataErrorsChanged);
112+
}
104113
}
105114
else
106115
{
107-
// comes new value, clear error
108-
if (errors != null && errors.Count != 0)
116+
if (previouslyHasErrors)
109117
{
110-
errors.Clear();
118+
// notify error was cleared.
111119
ErrorsChanged?.Invoke(this, ValueChangedEventArgs.DataErrorsChanged);
112120
}
113121
}

0 commit comments

Comments
 (0)