-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
[BUG] ValidationContext is not producing updates. #19
Comments
Hey @BenWhite27 👋, Thank you for opening an issue. We will get back to you as soon as we can. Also, check out our Open Collective and consider backing us. https://opencollective.com/reactiveui
|
Some more info. View Code Behind this.Bind(this.ViewModel, vm => vm.Username, v => v.userTxt.Text)
.DisposeWith(disposables);
this.Bind(this.ViewModel, vm => vm.Password, v => v.passTxt.Password)
.DisposeWith(disposables);
this.BindCommand(this.ViewModel, vm => vm.Login, v => v.loginBtn)
.DisposeWith(disposables);
this.BindValidation(this.ViewModel, v => v.errorsTxt.Text)
.DisposeWith(disposables); ViewModel public class SampleViewModel : ReactiveObject, ISupportsValidation
{
private ValidationHelper valHelper1;
private ValidationHelper valHelper2;
public SampleViewModel()
{
this.Login = ReactiveCommand.Create(() => { Debug.WriteLine("Login Invoked"); }, this.IsValid());
this.SetupValidations();
}
[Reactive] public string Username { get; set; } = "";
[Reactive] public string Password { get; set; } = "";
public ReactiveCommand<Unit, Unit> Login { get; }
public ValidationContext ValidationContext { get; } = new ValidationContext();
private void SetupValidations()
{
this.valHelper1 = this.ValidationRule(vm => vm.Username,
username => !String.IsNullOrWhiteSpace(username),
"The username cannot be empty");
this.valHelper1.ValidationChanged.Subscribe(change =>
{
Debug.WriteLine("valHelper1.ValidationChanged");
});
this.valHelper2 = this.ValidationRule(vm=>vm.Password,
password => password?.Length > 6,
"The password must be longer than 6");
this.valHelper2.ValidationChanged.Subscribe(change =>
{
Debug.WriteLine("valHelper2.ValidationChanged");
});
this.ValidationContext.ValidationStatusChange.Subscribe(change =>
{
Debug.WriteLine("ValidationContext.ValidationStatusChange");
});
this.ValidationContext.Valid.Subscribe(change =>
{
Debug.WriteLine("ValidationContext.Valid");
});
this.IsValid().Subscribe(valid =>
{
Debug.WriteLine("this.IsValid()");
});
}
} So whilst running the above and updating text in the ui controls I'll see debug console output like the following.
So whilst the rules are updating just fine the state for the whole object is valid all the time and allows me to execute the command. |
@alexmartinezm Mind having a look at this one? |
I will check it out over the weekend. Thank you for reporting this @BenWhite27. |
Thanks all. I'll download the source myself tonight when I get home and see if I can pin-point it further, I'm still a rookie with Reactive stuff though 😕 Edit - 16:54 |
Hi there, I'm trying to fix this bug, but I cannot reproduce this on a XF project and I don't have a Windows machine. However, I have a VM but the debug session is a bit slow. I hope to get this fixed this weekend. |
Thanks @alexmartinezm, I had a look at the code but struggled to get my head around it. If there's anything I can do let me know. I could setup a windows VM with Visual Studio and the repro for you to remote desktop into if that helps? When I was looking at the code I think everything inside BasePropertyValidation.cs was working, but the flow of sequences doesn't seem to get pass this observable.
|
@BenWhite27 for a temporary solution, try passing the new ValidationContext(); do this: // The ImmediateScheduler will make your sample work.
new ValidationContext(ImmediateScheduler.Instance); Currently,
ReactiveUI.Validation/src/ReactiveUI.Validation/Contexts/ValidationContext.cs Lines 83 to 88 in 0b28a7e
This issue takes place here due to DynamicData misuse. Feels like I've broken some stuff while migrating from ReactiveList<T> to SourceList<T> . The _validations collection is empty when _validationConnectable ticks on a scheduler other than ImmediateScheduler . Working on a fix now.
|
Describe the bug
ValidationContext does produce updates and current values do not reflect correct validation status or update in response to property changes.
Tested in a UWP project.
Steps To Reproduce
Create a Simple ViewModel and View with associated Bindings.
Create simple validation rules for the ViewModel
Create subscriptions to various Validation public APIs (ValidationContext.ValidationStatusChange, ValidationHelper.ValidationChange, etc.)
Run project and update text in View Controls
Observe that the behavior isn't as expected.
Expected behavior
I'd expect the ValidationContext to produce Observable sequeneces indicating the current status of the ViewModel's validation.
Environment
Additional context
I'm seeing updates to ValidationHelper.ValidationChanged in accordance with the associated Validation Rule, but no updates beyond the initial values from ValidationContext.
I've attached a bare bones project I've been using to identify this.
ReactiveUI.Validation.Sample.Uwp.zip
The text was updated successfully, but these errors were encountered: