Skip to content

Commit

Permalink
Fix BindableReactiveProperty validation
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Mar 1, 2024
1 parent e47c5b7 commit 0967a71
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/R3/BindableReactiveProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,24 @@ protected override void OnValueChanged(T value)
{
if (enableNotifyError)
{
// comes new value, require to clear error.
var previouslyHasErrors = (errors != null && errors.Count != 0);
errors?.Clear();

if (validationContext != null)
{
if (errors == null)
{
errors = new List<ValidationResult>(validationContext.ValidatorCount);
}
errors.Clear();

if (!validationContext.TryValidateValue(value, errors))
{
ErrorsChanged?.Invoke(this, ValueChangedEventArgs.DataErrorsChanged);

// set is completed(validation does not call before set) so continue call PropertyChanged
}
else if (previouslyHasErrors)
{
ErrorsChanged?.Invoke(this, ValueChangedEventArgs.DataErrorsChanged);
}
}
else if (validator != null)
Expand All @@ -101,13 +106,16 @@ protected override void OnValueChanged(T value)
{
OnReceiveError(error);
}
else if (previouslyHasErrors)
{
ErrorsChanged?.Invoke(this, ValueChangedEventArgs.DataErrorsChanged);
}
}
else
{
// comes new value, clear error
if (errors != null && errors.Count != 0)
if (previouslyHasErrors)
{
errors.Clear();
// notify error was cleared.
ErrorsChanged?.Invoke(this, ValueChangedEventArgs.DataErrorsChanged);
}
}
Expand Down

0 comments on commit 0967a71

Please sign in to comment.