# API
# Classes
The following are the main classes that an application will interface with.
# VRXForm
# hasError
Returns whether a field has errors
# Parameters
namestring 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');
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');
2
3
4
5
6
7
8
9
10
# getError
# Parameters
nameStringvalidationVRXFormValidatorType (optional, default"priorityMessage")
# 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(),
};
},
}
2
3
4
5
6
7
8
// can also import
import { VRXForm } from 'vrx-form'
export default {
data() {
return {
myForm: new VRXForm(),
}
}
}
2
3
4
5
6
7
8
9
10
# hasError
Returns whether a field has errors
# Parameters
namestring 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');
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');
2
3
4
5
6
7
8
9
10
# getError
# Parameters
nameStringvalidationVRXFormValidatorType (optional, default"priorityMessage")
# 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
typemessageoptions
# 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
REQUIREDstring use therequiredvalidator.PATTERNstring use thepatternvalidator.MAX_LENGTHstring use themax lengthvalidator.MIN_LENGTHstring use themin lengthvalidator.MINstring use theminvalidator.MAXstring use themaxvalidator.
# VRXFormValidator
Defines a validation for a field
Type: Object
# Properties
type(VRXFormValidatorTypes | VRXFormCustomValidator) The type of validation to be donevalidation(string | number) a number or string to validate against.messagestring what to include in errors if the validation fails.
# VRXValidator
# Parameters
typestring This is the unique name of the validator. Used to identifiy error messagesvalidationValue(string | number | boolean) What to validate againstmessagestring Sets the default message when the validation fails.validationValueRequiredboolean whether or not thevalidationValueis required.
# getMessage
Returns the specific message when a validation fails