cbValidation
Search…
Installation

Instructions

Just drop into your modules folder or use CommandBox to install
box install cbvalidation
The module will register several objects into WireBox using the @cbvalidation namespace. The validation manager is registered as [email protected]. It will also register several helper methods that can be used throughout the ColdBox application.

Mixins - Helper Methods

The module will also register the following methods in your handlers/interceptors/layouts/views
  • validate()
  • validateOrFail()
  • getValidationManager()
  • validatehasValue()
  • validateIsNullOrEmpty()
  • assert()
1
/**
2
* Validate an object or structure according to the constraints rules.
3
*
4
* @target An object or structure to validate
5
* @fields The fields to validate on the target. By default, it validates on all fields
6
* @constraints A structure of constraint rules or the name of the shared constraint rules to use for validation
7
* @locale The i18n locale to use for validation messages
8
* @excludeFields The fields to exclude from the validation
9
* @includeFields The fields to include in the validation
10
* @profiles If passed, a list of profile names to use for validation constraints
11
*
12
* @return cbvalidation.model.result.IValidationResult
13
*/
14
function validate()
15
16
/**
17
* Validate an object or structure according to the constraints rules and throw an exception if the validation fails.
18
* The validation errors will be contained in the `extendedInfo` of the exception in JSON format
19
*
20
* @target An object or structure to validate
21
* @fields The fields to validate on the target. By default, it validates on all fields
22
* @constraints A structure of constraint rules or the name of the shared constraint rules to use for validation
23
* @locale The i18n locale to use for validation messages
24
* @excludeFields The fields to exclude from the validation
25
* @includeFields The fields to include in the validation
26
* @profiles If passed, a list of profile names to use for validation constraints
27
*
28
* @return The validated object or the structure fields that where validated
29
* @throws ValidationException
30
*/
31
function validateOrFail()
32
33
/**
34
* Retrieve the application's configured Validation Manager
35
*/
36
function getValidationManager()
37
38
/**
39
* Verify if the target value has a value
40
* Checks for nullness or for length if it's a simple value, array, query, struct or object.
41
*/
42
boolean function validateHasValue( any targetValue )
43
44
/**
45
* Check if a value is null or is a simple value and it's empty
46
*
47
* @targetValue the value to check for nullness/emptyness
48
*/
49
boolean function validateIsNullOrEmpty( any targetValue )
50
51
/**
52
* This method mimics the Java assert() function, where it evaluates the target to a boolean value and it must be true
53
* to pass and return a true to you, or throw an `AssertException`
54
*
55
* @target The tareget to evaluate for being true
56
* @message The message to send in the exception
57
*
58
* @throws AssertException if the target is a false or null value
59
* @return True, if the target is a non-null value. If false, then it will throw the `AssertError` exception
60
*/
61
boolean function assert( target, message="" )
Copied!
Copy link
Edit on GitHub