Log In Sign Up
HomeExamplesValid Library: Custom Validation, Secondary Validation, and Examples of Events & Methods

Valid Library: Custom Validation, Secondary Validation, and Examples of Events & Methods

Category: Examples
The Valid validation module performs value validation on form fields. It requires the form field to have a 'name' attribute and is best used within a 'form' node. When submitting the form, 'validate' supports secondary validation. It also supports asynchronous Ajax validation. Built-in validations include value type checks, value strength checks, string inclusion checks, numerical range checks, and quantity checks. Additionally, it supports custom validation methods.

Custom Validation Types

When the built-in validation types don't meet requirements, users can extend their own validation types using the extend parameter. Basic syntax:

                
                new orca.Valid('#ID',{
                    extend:{
                        'mytype01':(param)=>{
                            return  {passed:true};
                        },
                    },
                    type:'mytype01'
                });
                
            

Important notes:

  1. The name defined in extend is what you use in type
  2. Extended types should be functions that return a standard object with at least a passed property
  3. The param parameter in custom validation contains:
    1. name: Field name being validated
    2. value: Field value being validated
    3. label: Field alias (defaults to name if not defined via options.label)
    4. type: Validation type name
    5. ins: Valid instance, providing access to internal variables/methods
    6. data: Reference value set in type (user-defined value/type)
  4. When using custom validation types in type, values can be omitted

Secondary Validation

Sometimes form values aren't entered via keyboard, so blur, change and input events won't trigger. Also, if form controls have validation, the form shouldn't submit if any validation fails.

For button, a or oc-btn form submission, manually validate using validTools.validForm before submitting.

Works with async validation too.

hide/show Methods

Validation containers persist after creation unless removed. Use hide() to hide and show() to display.

Event Listeners

There are 4 event listeners available: trigger, change, hide, and show:

Destruction

Use destroy() to remove an instance (only init() remains usable). Use init() to restore.

New Launch: 20% Off All Products

Unlock all examples and development resources