aiexandr / caliburn.micro.validation Goto Github PK
View Code? Open in Web Editor NEWSmall extension for Caliburn.Micro which enables fluent builder style validation rules
License: MIT License
Small extension for Caliburn.Micro which enables fluent builder style validation rules
License: MIT License
A manual call to Validate doesn't cause my bound controls validation errors to update.
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));
}
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?
Hello,
Can you please give us a simple demo app on which you've implemented this so I can better understand this one, Even one more project is available forked from your project but that also does not contain any examples.
I am very new to this validation field please do the needful.
Ref Git Repo : https://github.com/dingjimmy/Caliburn.Micro.FluentValidation
Thank you,
Some validation rules require async operations such as contacting a web service or database. Please add support for async validation.
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. ๐
Please make a NuGet package for this project.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.