Code Monkey home page Code Monkey logo

caliburn.micro.validation's People

Contributors

aiexandr 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

Watchers

 avatar  avatar  avatar

caliburn.micro.validation's Issues

Expression Lamda

Is possibile to scan the [MaxLength] and [Require] attribute from object and build validation rule?

protected void AutoBuildValidationRulesForObject<T>(T obj, string variableName)
        {


            foreach (var field in typeof(T).GetProperties())
            {
var maxLenghtAttr = (MaxLengthAttribute)field.GetCustomAttributes(typeof(MaxLengthAttribute), true).ToList().FirstOrDefault();
                var required = (ValidationAttribute)field.GetCustomAttributes(typeof(RequiredAttribute), true).ToList().FirstOrDefault();

                if (maxLenghtAttr != null)
                {


                    var variable = Expression.Variable(typeof(T), variableName);
                    var pe = Expression.Property(variable, typeof(T), field.Name);
                    var left = Expression.Property(pe, typeof(string).GetProperty("Length"));
                    var right = Expression.Constant(maxLenghtAttr.Length, typeof(int));
                    var e2 = Expression.LessThanOrEqual(left, right);
                    var predicate = Expression.Lambda<Func<bool>>(e2);
                    if (required != null)
                        AddValidationRule(() => variable).Condition(predicate).Message(required.ErrorMessage);
                    else
                        AddValidationRule(() => variable).Condition(predicate).Message(string.Format("{0} Must be Less then of {1}", field.Name, maxLenghtAttr.Length));
                }

Example usage

Could you provide an example how to use it in a view (for example using a Textbox)?
Would I need to overwrite the Validation.ErrorTemplate in order to show the error message in my texthox?

Async Validation

Some validation rules require async operations such as contacting a web service or database. Please add support for async validation.

Check if a Validation Error still Exists

How do I check if a validation error still exists?

Is there a property or method that I can use to check for existing validation errors?

It would be very convenient if there is a HasError property (or something similar) that will indicate that there are still validation errors. We can then bind this property to the IsEnabled property of a button and use a converter to invert the value so that the button will only be clickable if there are no validation errors left. Or just return !HasError in the CanButtonName method. ๐Ÿ˜„

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.