Filed under: javascript

VanadiumJS

Vanadium is declarative client-side validation toolkit. These declaration can be done in two different ways:
  • Using json structure

    This method requires that elements under validation have to have their IDs defined. Granted that, one can declare validation of the form from [example] by including following code:
    var VanadiumRules = {
            email: ['required', 'email'],
            accept: ['accept'],
            desc: ['required']
            }
  • Using inline markup

    This method simply uses special markup in html elements' class attributes. The markup is very straightforward. It is consists up to three tokens, prepended with special prefix distinguishing the markup from regular CSS names and separate by special separator. The prefix and the separator are customizable and can be any string. The default prefix is : (colon) and the separator is ; (semicolon). The first token, which is mandatory, is validator type name. The second one is the parameter for the validator. E.g. number of characters when length validator is used. The third token is the ID of the html element serving as an advice into which the message informing about validation failure is inserted. Said that, a html for an element being required valid email address with advice of ID adv would look like:
    <div id="adv" style="display:none"> the element is required and should be valid email address </div>
            <input id="email :required;;adv :email;;adv" type="text"/>
    As you can see the double semicolon is used denoting simply no parameter for validator type is provided.