cbValidation
v2.x
v2.x
  • Introduction
  • Intro
    • Release History
      • What's New With 2.1.0
      • What's New With 2.0.0
    • About This Book
      • Author
  • Overview
    • Installation
    • Configuration
    • Declaring Constraints
      • Configuration File
      • Domain Object
      • A-la-carte
    • Available Constraints
      • Custom Message Replacements
      • Constraint Custom Messages
    • Validating Constraints
      • Validating With Failures
      • Validating with shared constraints
      • Validating with a-la-carte constraints
      • Validating Custom Fields
      • Validating With Profiles
    • Displaying Errors
    • WireBox Integration
  • Advanced
    • Custom Validators
    • Unique ORM Validator
    • i18n Integration
    • Custom Validation Managers
Powered by GitBook
On this page
  • Defining Profiles
  • Validating Profiles

Was this helpful?

Edit on Git
Export as PDF
  1. Overview
  2. Validating Constraints

Validating With Profiles

cbValidation 2.x series introduced the ability to validate using field profiles. This will allow you to define all your constraints but also define field profiles where you can define only certain fields to be validated if the profile name is used.

Defining Profiles

This is using the this.constraintProfiles struct literal:

this.constraintProfiles = {
	"new" = "fname,lname,email,password",
	"update" = "fname,lname,email",
	"passUpdate" = "password,confirmpassword"
}

The key is the name of the profile and the value is a list of the fields to validate if the profile is targeted for validation.

Validating Profiles

Every validation method: validate(), validateOrFail() has a profiles argument. You can then pass one or more to the argument so you can validate 1 or more profiles:

var results = validateModel( target=model, profiles="update" )
var results = validateModel( target=model, profiles="update,passUpdate" )
PreviousValidating Custom FieldsNextDisplaying Errors

Last updated 5 years ago

Was this helpful?