UserFrosting API

JqueryValidationAdapter extends ClientSideValidationAdapter

JqueryValidationAdapter Class.

Loads validation rules from a schema and generates client-side rules compatible with the jQuery Validation JS plugin.

Tags
author

Alex Weissman (https://alexanderweissman.com)

Table of Contents

$schema RequestSchemaInterface
$translator Translator
rules() Generate jQuery Validation compatible rules from the specified RequestSchema, as a JSON document. string|array
transformValidator() Transform a validator for a particular field into one or more jQueryValidation rules. mixed
__construct() Create a new client-side validator. mixed
setSchema() Set the schema for this validator. mixed
setTranslator() Set the translator for this validator, as a valid MessageTranslator object. mixed
rules() Generate and return the validation rules for this specific validation adapter. mixed

Properties

Methods

rules()

Generate jQuery Validation compatible rules from the specified RequestSchema, as a JSON document.

public rules( [ $format : string = 'json' ] [, $stringEncode : bool = false ] [, $arrayPrefix : string = '' ] ) : string|array

See this as an example of what this function will generate.

Parameters
$format : string = 'json'

(Default: json)

$stringEncode : bool = false

Specify whether to return a PHP array, or a JSON-encoded string. (default: false)

$arrayPrefix : string = ''

(Default: '')

Return values
string|array

Returns either the array of rules, or a JSON-encoded representation of that array.

transformValidator()

Transform a validator for a particular field into one or more jQueryValidation rules.

protected transformValidator( $fieldName : string , $validatorName : string , $validator : string[] ) : mixed
Parameters
$fieldName : string
$validatorName : string
$validator : string[]
Return values
mixed

setTranslator()

Set the translator for this validator, as a valid MessageTranslator object.

public setTranslator( $translator : Translator ) : mixed
Parameters
$translator : Translator

A Translator to be used to translate message ids found in the schema.

Return values
mixed

rules()

Generate and return the validation rules for this specific validation adapter.

public abstract rules( [ $format : string = 'json' ] [, $stringEncode : bool = true ] ) : mixed

This method returns a collection of rules, in the format required by the specified plugin.

Parameters
$format : string = 'json'

The format in which to return the rules. For example, "json" or "html5".

$stringEncode : bool = true

In the case of JSON rules, specify whether or not to encode the result as a serialized JSON string.

Return values
mixed

The validation rule collection.

Search results