Created
August 9, 2010 19:25
-
-
Save jmarnold/515951 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HelloWorldHtmlConventions : DefaultHtmlConventions | |
{ | |
private readonly ValidationGraph _graph; | |
public HelloWorldHtmlConventions(ValidationGraph graph) | |
{ | |
_graph = graph; | |
Editors | |
.If(a => a.Accessor.FieldName.Contains("Password")) | |
.Modify(t => t.Attr("type", "password")); | |
Editors | |
.Always | |
.Modify(ModifyWithValidationGraph); | |
} | |
private void ModifyWithValidationGraph(ElementRequest request, HtmlTag tag) | |
{ | |
// check for partials | |
var modelType = (request.Accessor is SingleProperty) | |
? request.Model.GetType() | |
: request.Accessor.OwnerType; | |
var calls = _graph | |
.FindChain(modelType) | |
.CallsFor(request.Accessor.FieldName); | |
calls | |
.Where(call => !typeof(ComparisonValidationRule<>).IsAssignableFrom(call.RuleType)) | |
.Each(call => tag.Modify(t => t.AddClass(call.ToRuleDef().Name.ToLower()))); | |
tag.Attr("id", request.ElementId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment