Git Product home page Git Product logo

validar's People

Contributors

dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar msieker avatar simoncropp avatar tom-englert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

validar's Issues

The code for FluentValidation Validation Template Implementation in the readme.md is wrong

target is not a IValidationContext.

public ValidationTemplate(INotifyPropertyChanged target)
{
    this.target = target;
    validator = GetValidator(target.GetType());
    validationResult = validator.Validate(target); // target is not a IValidationContext.
    target.PropertyChanged += Validate;
}

void Validate(object sender, PropertyChangedEventArgs e)
{
    validationResult = validator.Validate(target); // target is not a IValidationContext.
    foreach (var error in validationResult.Errors)
    {
        RaiseErrorsChanged(error.PropertyName);
    }
}

Netstandard Support

Is it possible to add Netstandard support? Fody and propertychanged.fody already have it. It would be nice if you can add it for this weaver.

Thanks.

PropertyChanged notification for HasErrors

Try as I might, I can't seem to get Validar.Fody and PropertyChanged.Fody to play nicely together. Everything works great except for triggering a PropertyChanged notification on the HasErrors property.

WPF Framework 4.0 validation of complex object

Hello,
I'm tring to validate a quite simple model under WPF (in real case I use Caliburn Micro as MVVM framework)

My problem is that I can't disable an confirm button if there're error in the nested model's property

consider this case

public class MainObjectValidator : AbstractValidator<MainObject>
{
    public MainObjectValidator()
    {
        RuleFor(x => x.Child).SetValidator(new ChildObjectValidator());
        RuleFor(x => x.Name).NotEmpty();
    }
}

[InjectValidation]
public class ChildObject : INotifyPropertyChanged
{
    private int age;

    public int Age
    {
        get
        {
            return this.age;
        }
        set
        {
            this.age = value;
            NotifyPropertyChanged("Age");
        }
    }

    private void NotifyPropertyChanged(String propertyName = "")
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
}


public class ChildObjectValidator : AbstractValidator<ChildObject>
{
    public ChildObjectValidator()
    {
        RuleFor(x => x.Age).GreaterThan(18);
    }
}

and Here's my ViewModel

public class ViewModel : ViewModelBase
{
    private MainObject dummy;

    public MainObject Dummy
    {
        get
        {
            return this.dummy;
        }
        set
        {
            this.dummy = value;
            OnPropertyChanged(() => Dummy);
        }
    }

    public ViewModel()
    {
        this.Dummy = new MainObject();

        Dummy.Child.Age = 15;
        Dummy.Name = "paolo";

        CreateLoadCommand();
    }

    private void CreateLoadCommand()
    {
        LoadDataCommand = new RelayCommand(this.DoSomething());

    }

    public ICommand LoadDataCommand
    {
        get;
        internal set;
    }

    public bool CanLoadDataCommand
    {
        get
        {
            return false;
        }

    }

    private Action DoSomething()
    {
        return () =>
            {

                var x = Dummy.GetType().GetField("validationTemplate", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.FlattenHierarchy);

                var t = (ValidationTemplate)x.GetValue(Dummy);
            };
    }
}

and my View

<code>
Window x:Class="WPFExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
        Title="MainWindow" Height="350" Width="525">
    <Grid DataContext="{Binding}">
        <Grid.RowDefinitions>
            <RowDefinition Height="25"></RowDefinition>
            <RowDefinition Height="25"></RowDefinition>
            <RowDefinition Height="25"></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>

        <Label Content="Name" Grid.Column="0" Grid.Row="0"></Label>
        <Label Content="Age" Grid.Column="0" Grid.Row="1"></Label>
        <TextBox Text="{Binding Dummy.Name, Mode=TwoWay, ValidatesOnDataErrors=True}" Grid.Row="0" Grid.Column="1"></TextBox>

        <telerik:RadMaskedNumericInput Value="{Binding Dummy.Child.Age, Mode=TwoWay, ValidatesOnDataErrors=True}" Grid.Row="1" Grid.Column="1"></telerik:RadMaskedNumericInput>
        <Button Content="Ok" Grid.Row="2" Grid.ColumnSpan="2" Command="{Binding LoadDataCommand}"></Button>
    </Grid>
</Window>
</code>

Even if on screen Age field get's red I can't disable the button, if I look at the value of

var t = (ValidationTemplate)x.GetValue(Dummy);

t.HasError it's always true

I've used ValidationTemplate present in your homepage

Could not load type

If I am use custom attribute and InjectValidationAttribute, i get runtime exception
If I use a custom attribute with an InjectValidationAttribute, an exception occurs at run time, when the following code is executed:
public ValidationTemplate(T target)
{
var attributes = target.GetType().GetCustomAttributes(false).ToList();
}
Exception:
An exception of type 'System.TypeLoadException' occurred in mscorlib.dll but was not handled in user code
Additional information: Could not load type "Validar.InjectValidationAttribute" from assembly "PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

Missing the InjectValidation attribute

It's written in the project page that I should mark my class with InjectValidation attribute but it's not there ... I downloaded the library via NuGet and there were no refrence added (just the after build task)

Using Validar with a sealed class creates CA errors.

[ImplementPropertyChanged, InjectValidation]
public sealed class MyClass : INotifyPropertyChanged
{

creates the following static code analysis errors:

Microsoft.Design : ''MyClass.IDataErrorInfo.Error.get()'' is a virtual member declared in a sealed type.
Mark the member non-virtual or, if the type should be extensible, unseal it.

(same error repeated for all other interfaces members)

Only the UI can get the validation error info?

It seems only the UI can get the error info. in a mvvm scenario,how viewmodel get the validation info? only by reflection?
eg. create a new user, but the username is invalid. although the UI show the notification, the register button is valid. The button's event handler should inspect the model's validation info.At this time,I can't get the info I want,because when I code, the code doesn't generated. I should use reflection or validate the model again?

Couldn't access INotifyDataErrorInfo members on view-model by another method

Hi @SimonCropp, First thanks for the library.
Definitely [InjectValidation] works great, saves time and makes class more readable.

However when I would like to access INotifyDataErrorInfo members on my view-model in another method, its not possible now. because INotifyDataErrorInfo members are implemented at build time by [InjectValidation].

For Example,

public class ValidationTemplate : INotifyDataErrorInfo   // General Validation Template
{
     // Implementation of INotifyDataErrorInfo
}

[InjectValidation]
Public class User : INotifyPropertyChanged   // View Model
{
    [MaxLength(20)]
    public string Name{ get; set; }

    internal bool IsError()   // Internal method required
    {
          return HasErrors;    // Error since HasErrors implemented at build time by [InjectValidation]
    }
}

This issues may be similar to #5

Validations visible when resetting or clearing values in ViewModel - allow reset for validation too.

Hi. Thanks for the library. One question. When user is done with input on the form, saves the data and then I have to clear, or reset bindings in ViewModel for the next use, validations pops up right from the start on showing form again. I get that this can be expected since now validation is failing, but there should be a way to say - this is clean state, track the input and validate again. I don't see an option to somehow reset or clear validation errors as well, without calling validation template, which beats the purpose of Inject validation if you ask me.

I'm using Validar + FluentValidation nuget package.
Validar : 1.8.0
FluentValidation 8.6.2
WPF application running on top of .NET CORE 3.1

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.