# API

# Classes

The following are the main classes that an application will interface with.

# VRXForm

# hasError

Returns whether a field has errors

# Parameters

  • name string name of the field that needs input.

# Examples

// if your data looks like the following:
myData: {
  myInput: null
}

// errors can be retrieved by
myForm.hasError('myInput');
1
2
3
4
5
6
7
// for deeply nested validation.
// if your data looks like the following:
myData: {
 someEntity: {
   myInput: null
 }
}

// errors can be retrieved by
myForm.hasError('someEntity.myInput');
1
2
3
4
5
6
7
8
9
10

# getError

# Parameters

# setValidations

Sets the validators that will validate the fields. Once init is called this can no longer be set.

# Parameters

  • validators ...VRXFormDataValidator the validators to validate each field.

Returns VRXForm returns self for chaining.

# clearForm

Clears the form back to a blank state. Please Note that this does not send it back to its original state.

# init

The final step in the form setup. Once the data is submitted and the validators are added, init has to be called to start the process of validation.

# getValidators

Returns the current validator object.

# VRXForm

Creates a form object that can do validations

# Examples

// To initialize
export default {
   data() {
     return {
       myForm: this.$createForm(),
     };
   },
}
1
2
3
4
5
6
7
8
// can also import
import { VRXForm } from 'vrx-form'

export default {
   data() {
     return {
       myForm: new VRXForm(),
     }
   }
}
1
2
3
4
5
6
7
8
9
10

# hasError

Returns whether a field has errors

# Parameters

  • name string name of the field that needs input.

# Examples

// if your data looks like the following:
myData: {
  myInput: null
}

// errors can be retrieved by
myForm.hasError('myInput');
1
2
3
4
5
6
7
// for deeply nested validation.
// if your data looks like the following:
myData: {
 someEntity: {
   myInput: null
 }
}

// errors can be retrieved by
myForm.hasError('someEntity.myInput');
1
2
3
4
5
6
7
8
9
10

# getError

# Parameters

# setValidations

Sets the validators that will validate the fields. Once init is called this can no longer be set.

# Parameters

  • validators ...VRXFormDataValidator the validators to validate each field.

Returns VRXForm returns self for chaining.

# clearForm

Clears the form back to a blank state. Please Note that this does not send it back to its original state.

# init

The final step in the form setup. Once the data is submitted and the validators are added, init has to be called to start the process of validation.

# getValidators

Returns the current validator object.

# VRXFormCustomValidator

# Parameters

  • type
  • message
  • options

# validate

Validates the field. Must be overwritten

  • Throws any Will throw a no implementation error, if not overwritten

# getMessage

Returns the set message on initialization

# Types

The following are the types that are used to define aspects of the above classes.

# VRXFormValidatorType

Valid built in validations

Type: Object

# Properties

  • REQUIRED string use the required validator.
  • PATTERN string use the pattern validator.
  • MAX_LENGTH string use the max length validator.
  • MIN_LENGTH string use the min length validator.
  • MIN string use the min validator.
  • MAX string use the max validator.

# VRXFormValidator

Defines a validation for a field

Type: Object

# Properties

  • type (VRXFormValidatorTypes | VRXFormCustomValidator) The type of validation to be done
  • validation (string | number) a number or string to validate against.
  • message string what to include in errors if the validation fails.

# VRXValidator

# Parameters

  • type string This is the unique name of the validator. Used to identifiy error messages
  • validationValue (string | number | boolean) What to validate against
  • message string Sets the default message when the validation fails.
  • validationValueRequired boolean whether or not the validationValue is required.

# getMessage

Returns the specific message when a validation fails