logo

New Response

« Return to the blog entry

You are replying to:

  1. Of course there are benefits. I mentioned adding a widget more than once to a form a couple of days ago. So to extend the example, you could create a couple of objects, say FormValidator and ValidatorRule. Your FormValidatorInit could receive a string array of fieldnames, and maybe RegEx pattern pairs, with which it would create a chiled collection or array of ValidatorRule objects. FormValidator.isValid would be called from your onsubmit and would simply need to query each Validator.Rule.isValid method to see if FormValidator.isValid returns true or false.

    That's the rough workflow. The object topography would of course be a bit more detailed, but you get the idea. Now I can init FormValidator with multiple fields (or other things), each of which simply becomes a ValidatorRule, which can contain all the methods I need for each items validation logic based on how it was initialized by FormValidator.

    Very useful when I don't have to unravel miles of conditional logic, or rewrite said lagic, everytime I add a field.

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment: