Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript form-validation framework: Request for Review
    primarykey
    data
    text
    <p>I wasn't sure if I could ask this kind of question, but after seeing <a href="https://meta.stackexchange.com/questions/1957/should-so-allow-give-me-some-feedback-questions">this</a> on Meta Stackoverflow, it looks like this kind of question is ok. Well, onto my question:</p> <p>A few months ago I wrote a validation framework in Javascript. I know that there already exist validation frameworks like <a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/" rel="nofollow noreferrer">jQuery Validation</a>, but I wanted to take a different approach to validation. Current approaches deal with writing Javascript code to perform validation on form elements. By looking at the form source code, it is not immediately evident what validation occurs on each element. To some extent this can be remedied by using CSS classes that specify different kinds of validation. But I felt that even this was limited because you cannot easily customize the behavior of the validaton (error messages, etc.). I wanted to do something like annotation-based validation in Java using <a href="http://people.redhat.com/~ebernard/validation/" rel="nofollow noreferrer">JSR-303 Bean Validation</a> or <a href="http://docs.jboss.org/hibernate/validator/4.0.1/reference/en/html/validator-gettingstarted.html" rel="nofollow noreferrer">Hibernate Validator</a>.</p> <p>Since HTML5 allows you to add custom attributes to an elements, I figured that I could leverage this to "annotate" form elements for validation. So, essentially, I came up with this:</p> <pre><code>&lt;input id = "myInput" name = "myInput" type = "text" class = "regula-validation" data-constraints = '@NotEmpty @IsNumeric @Between(min=1, max=5)' /&gt; </code></pre> <p>With this basic idea in mind, I created a Javascript framework that:</p> <ul> <li>Examines the DOM for elements that have constraints defined and binds these constraints to the elements</li> <li>Allows the creation of custom constraints</li> <li>Allows programmatic binding of constraints</li> <li>Validates bound constraints</li> </ul> <p>In addition, the framework has the following features:</p> <ul> <li>Validation groups, similar to that specified in JSR-303</li> <li>Interpolation for error messages</li> </ul> <p>Once I created my framework I tried to get feedback and review for it but I wasn't sure where to go to get feedback and review. I wrote a few blog posts about it and posted it to Digg and Reddit (programming section) without much luck. A few people seemed interested, but I didn't get much more than that.</p> <p>Recently, at my workplace we've been modernizing a legacy codebase (JSP and servlets) and moving it into Spring MVC. When the conversation of validation came up, I pitched my framework to my senior architect. I did a little integration and proof of concept and they seemed interested and gave me the go-ahead to add it to the project. Till now, I only had my own humble opinion that this would be a helpful way to do validation, so this gave me some confidence that my idea and framework might have some merit. However, I still needed some more participation and framework. After I figured out that Stackoverflow does allow these kinds of questions, I decided to post it on here to get some constructive criticism, comments, and feedback.</p> <p>So without any more delay, I'd like to introduce <a href="http://wiki.github.com/vivin/regula/" rel="nofollow noreferrer">Regula</a>. The link I have provided goes to a wiki on GitHub that has all the documentation for the framework. You can download the latest version (v1.1.0) from <a href="http://github.com/vivin/regula/downloads" rel="nofollow noreferrer">here</a>.</p> <p>Looking forward to your comments.</p> <p><strong>Some extra information that is not immediately relevant</strong></p> <p>I had toyed with the idea of integrating my framework with Spring, i.e., translating the validation annotations on beans into client-side validation. Recently I was able to get this to work, even with validation groups (although there is no support currently for inheritance relations between the groups on the client side). This way, you simply have to annotate field properties with the validation constraints, and client-side validation-code is automatically generated. However, I am a Spring novice and so my method is probably not that clean. I would like to get some feedback on this as well, so if anyone is interested please let me know. Ideally (and I hope I am not being too pretentious) I would like to contact the Spring folks and see if they are interested in this.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COI don't really have a use case to really exercise it; but, I will vote and favorite, since it seems like a good concept. I am curious to see what people make of it. My choice of web framework, wicket, mostly eliminates the need for javascript validation, since it provides faculties for submitting data and producing feedback from the server via ajax request. I know that other frameworks, like ASP.NET, do encourage client-side validation for dynamic feedback (though you always need to do server validation on form submission).
      singulars
    2. CO@RMorrisey thanks for your comment! I haven't tried out wicket, but I'd like to take a look at it sometime. I think JSF also does something similar to what you describe. At work we have some validation that is only done on the server-side. With my framework I've been able to do it client-side like the way you describe. I have a custom constraint with a validator that makes an AJAX request to perform validation. Thanks once again for your feedback!
      singulars
    3. COI know it is off topic and off time for this, but how did you inject the annotation to the data constraints? I came to the question while looking on how to do something similar (regula is more than enough for my needs)
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload