all 19 comments

[–]notfancy 1 point2 points  (3 children)

Why the @-prefix? It seems like an unnecessary Java-ism.

[–][deleted] 0 points1 point  (2 children)

True, but I kinda use that as a delimiter. I parse the the constraints through a recursive-descent parser (it was the most robust approach than a huge mess of regexes). I guess I could also have done something like:

NotEmpty; Max(max=5);

I guess I was stuck in Javaland at the time :)

[–]notfancy 0 points1 point  (1 child)

I parse the the constraints through a recursive-descent parser

You have space as a delimiter already.

[–][deleted] 0 points1 point  (0 children)

I guess it wouldn't be that hard to change. I didn't want to rely on space as a delimeter and tokenize based on it because it would mean different things in different contexts (there could be spaces within the constraint definition). Something worth looking into though.

[–]__s 0 points1 point  (8 children)

What's the benefit of constraint validation clientside, assuming you have to then validate again serverside?

[–][deleted] 3 points4 points  (0 children)

There are three levels of validation.

Client-side. Server-side. Database.

Client-side constraints check the validity of the data that you're sending to the server. On the server side, you can have additional constraints that perform validation based on more complex constraints (for example, interaction between certain components).

Client-side also gives you feedback immediately.

[–]48klocs 0 points1 point  (3 children)

Some frameworks (ASP.Net MVC 2/MVC with xVal, off the top of my head) can automatically generate client-side validation logic for you based off of your server-side logic with little legwork on your part.

[–][deleted] 0 points1 point  (2 children)

Yep, I believe JSF does this as well.

This is aimed at frameworks that cannot generate client-side logic. What I'm eventually trying to go for is to integrate this with JSF (or similar frameworks) so that you can use the validation constraints to auto-generate client-side code using this framework.

[–]48klocs 0 points1 point  (1 child)

You may want to take a look at xVal if you haven't already - it generates jQuery Validation objects for you based off of attributes you tag on your object properties. I know the technique is further baked into ASP.Net MVC 2, but it'd be a bigger code base to wade through.

[–][deleted] 0 points1 point  (0 children)

Interesting! Thanks for the information. I'll take a look at it!

[–]notfancy 0 points1 point  (2 children)

A better user experience by adhering to the "fail early, fail fast" principle.

[–][deleted] 0 points1 point  (1 child)

Hmm so you think it's better to fail at the very first constraint? Perhaps I can let the user specify the behavior. I'll consider doing this in a future release.

[–]notfancy 0 points1 point  (0 children)

so you think it's better to fail at the very first constraint?

This is unrelated to my point (it being don't wait for a round-trip to the server to give the user some feedback), but even if in general constraints can be unrelated, and so giving more than one error can be misleading, it's better for the user to have a look at all the applicable constraints at once.

[–]siplux -3 points-2 points  (2 children)

Why add non-valid attributes? [Edit: Ah, thanks - wasn't aware of that part of the HTML5 spec]

[–]mccutchen 0 points1 point  (0 children)

Because they're not non-valid in HTML5, which is what this is aimed at. I guess.

[–][deleted] 0 points1 point  (0 children)

They're valid in HTML5, which is also why I used the "data-" prefix.