4 ms·
This is a clean way to solve the low hanging fruit of form validation, stuff like isItAnEmailAddress(). What I always find messy in web frameworks is doing val
by jiggy2011 14y ago
This is a clean way to solve the low hanging fruit of form validation, stuff like isItAnEmailAddress().
What I always find messy in web frameworks is doing validations which are more complicated.
For example a radio button choice which hides another form element which would otherwise be mandatory but should now not be filled in at all. Or where supplying a value between certain dates changes another date field from optional to mandatory and also must check that these dates are between certain values dictated by the first date field.
- chime 14y agoFor one of my new projects, that is precisely what I am doing - making it possible to define complicated validation rules in a simple manner (and lots more). Would there be interest if we open-source it?
- handzhiev 14y agoOf course :)
- jiggy2011 14y agoQuite possibly. Though I'm not sure how much this could be generalised since complex validation rules are effectively computer programs in themselves. Not sure what your approach to this problem is, but perhaps one way to do it would be a validation engine that is inherently functional by design. Of course, ideally it should be something that can plug in to popular web frameworks easily.
- ryaf 14y agoData binding solves this generically. It allows you to build state machine trivially Stuff like angular and ember do this amazingly well though it would be nice to have a nice standalone library. (no idea if one exists)
- esailija 14y agoUsing a declarative DSL designed for validation rules should make it much simpler, it would minimize the amount of writing the boilerplate stuff that comes with a general purpose language and would focus solely on the actual validation rules. It could be used in the same way as templating for javascript is used, a script element with a custom type or validation-src attribute in the form or something.
- sergiotapia 14y agoWould love to see something like this, and if it's useful and easy to drop in, I'd use it.
- DennisP 14y agoKnockoutjs is nice for that sort of thing. They have a pretty quick tutorial: http://learn.knockoutjs.com/ http://learn.knockoutjs.com/