views:

359

answers:

3

I've been looking and it seems no-one has cracked this yet but I thought I'd ask the community here as well to see if anything came up.

Is there a way to get client-side validation (jQuery, Live Validation, whatever) to automagically get the validation rules from LLBLGen's built in validation?

LLBLGen (and others like Subsonic) already know that a field can't be null, must be less than 100 characters, etc and seems useful not to have to keep setting these all over the place.

A: 

Jquery.Validate is pretty awsome. It can validate credit card numbers, dates, min and max characters, and many other features. The link is here and it is very simple to use.

http://docs.jquery.com/Plugins/Validation

Basically all you do is register the .js file when loading up your page and when declaring the class of an input, put in "validate" or "validate date" or whatever and it will intelligently do it for you. Again they give examples and documentation in the link. Hope this helps you.

Al Katawazi
I want something that would enforce server side validation as well as client-side validation. Just like the webforms validators.
William
Well you are SOL in this case. You want to create a seperation of concerns between what is happening on your view and what is happening in the code behind/controller. Sometimes that means duplicate code doing the same thing, just somethign we have to deal with, sorry.
Al Katawazi
Also how the heck are you going to have both client side and server side validation without posting to the server to check? are you going to have a generic handler check every keystroke sent via jquery post? Its an option but you have to do the leg work.
Al Katawazi
No. I want to set the validation rules in one place and have them enforced (the simple ones anyway) on the client side and server side without any extra coding. Seems like a pipe dream :(
William
One word - "xVal". See below.
Charlino
A: 

I'd say one has to create proper templates to ouput whatever validation code you want (or modify exisiting ones). I am not sure whether there are any existing but you can create them by yourself - it is pretty easy.

HTH

Miha Markic
+1  A: 

Check out xVal... it generates jQuery Validation based on validation found in your models.

xVal @ CodePlex

Introduction to xVal blog post

I don't know how LLBL validation works or if there is any native support for it in xVal. But if there isn't, it would just be a matter of creating an IRulesProvider - no doubt it would come in handy to numerous other LLBL users.

I think something similar was done for the LightSpeed ORM. See here MVC and LightSpeed – Part 4 – Model Binding

Charlino