# 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');
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
name
Stringvalidation
VRXFormValidatorType (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
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');
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
name
Stringvalidation
VRXFormValidatorType (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
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 therequired
validator.PATTERN
string use thepattern
validator.MAX_LENGTH
string use themax length
validator.MIN_LENGTH
string use themin length
validator.MIN
string use themin
validator.MAX
string use themax
validator.
# 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.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 messagesvalidationValue
(string | number | boolean) What to validate againstmessage
string Sets the default message when the validation fails.validationValueRequired
boolean whether or not thevalidationValue
is required.
# getMessage
Returns the specific message when a validation fails