Git Product home page Git Product logo

Comments (8)

alexmartinezm avatar alexmartinezm commented on May 2, 2024 2

I will check it out over the weekend. Thank you for reporting this @BenWhite27.

from reactiveui.validation.

worldbeater avatar worldbeater commented on May 2, 2024 1

@BenWhite27 for a temporary solution, try passing the ImmediateScheduler.Instance to your ValidationContext constructor. Instead of doing this:

new ValidationContext();

do this:

// The ImmediateScheduler will make your sample work.
new ValidationContext(ImmediateScheduler.Instance);

Currently, _validationSource and _validations won't stay synchronized without the ImmediateScheduler due to the following code blocks:

.CountChanged()
.Count()
.StartWith(0)
.Select(_ =>
_validations
.Select(v => v.ValidationStatusChange)

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.

from reactiveui.validation.

open-collective-bot avatar open-collective-bot commented on May 2, 2024

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

PS.: We offer priority support for all backers. Don't forget to add priority label when you start backing us 😄

An advanced, composable, functional reactive model-view-viewmodel framework for all .NET platforms!

from reactiveui.validation.

BenWhite27 avatar BenWhite27 commented on May 2, 2024

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.

// These are the initial values coming from the observables.
valHelper1.ValidationChanged
valHelper2.ValidationChanged
ValidationContext.ValidationStatusChange
ValidationContext.Valid
this.IsValid()

// These are during the test
valHelper1.ValidationChanged
valHelper2.ValidationChanged
valHelper2.ValidationChanged
valHelper1.ValidationChanged
Login Invoked

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.

from reactiveui.validation.

glennawatson avatar glennawatson commented on May 2, 2024

@alexmartinezm Mind having a look at this one?

from reactiveui.validation.

BenWhite27 avatar BenWhite27 commented on May 2, 2024

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
More info.
Adding another ValidationRule at a later point via a command suddenly triggers an update from all objects and I can see some validation errors displayed in the UI. The first 2 rules then seem to function properly but the newly added rule doesn't behave correctly, almost as though the text it's producing is 1 property change behind the current value.

from reactiveui.validation.

alexmartinezm avatar alexmartinezm commented on May 2, 2024

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.

from reactiveui.validation.

BenWhite27 avatar BenWhite27 commented on May 2, 2024

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.

_validationConnectable = validationChangedObservable

from reactiveui.validation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.