FubuMvcArchive / fubuvalidation

FubuValidation -- have validation your way, whatever way that happens to be

Home Page:http://validation.fubu-project.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ValidationBehavior and ModelBindingErrors

emiaj opened this issue · comments

There is a problem on how the ValidationBehavior and ModelBindingErrors interact each other.
We have an scenario where we perform calls to ContinueValidation to validate nested properties.
We are using the validation infrastructure to perform an ajax validation preview of the form about to be posted to the server.
When a nested property is not valid, we get back the exact field name thanks to the nested accessor magic (which coincides with the html element id), that allow us to attach UI hints to these faulting elements and let the user know that the inputted data is not correct because X reasons.
This is not the case for binding errors.
https://github.com/DarthFubuMVC/fubuvalidation/blob/master/src/FubuMVC.Validation/ValidationBehavior.cs#L40
https://github.com/DarthFubuMVC/fubuvalidation/blob/master/src/FubuMVC.Validation/ModelBindingErrors.cs#L27
The ModelBindingErrors class only attach the PropertyInfo objects to the Notification instance, losing the context of the exact position of it in the properties graph.
So, instead of getting "Complex.FooBar.Baz" back as field, we get "Baz" as field, making impossible to effectively attach those UI hints at the right targets, or what's worse, link this error to a "Baz" html element that comes from the root of the model of our views (Model.Baz).
Hope this makes sense.

@emiaj Was there a similar issue opened up against Model binding to track the errors via an Accessor? That would solve this.

@jmarnold I asked about this in the mailing list....
https://groups.google.com/forum/#!topic/fubumvc-devel/dwN4w554lF8/discussion
Just wanted to put it here so you guys could look it up easier.

But certainly that would do the trick.

We also went custom mode (created our own Accessor/IValueGetter) to get the "field" value correctly for collection items, but that's another story.
E.g.: SomeCollection[4].SomeProperty

@emiaj Ok, so what is the solution to this? I mean, is it FubuCore or FubuValidation that needs fixing?

@ahjohannessen One is to make ModelBindingErrors a bit smarter and, somehow, change it to be able to walk through the model type and build the accessor object from the PropertyInfo, but honestly I don't know if this is possible or a valid solution.
The second option would be to change FubuCore and IFubuRequest to get a Accessor based datastructure. I tried to update FubuCore but the changes were so many and I thought it may be better to raise the issue here before (never finished the update, though).

We're going to have to revisit this one after the new HTML conventions work.

@jeremydmiller is convinced he can make this work. I'm going to close this.