Skip to content
PHP Ecosystem
Explore

ClientValidatorScriptInterface

API reference › yii › validators › client › ClientValidatorScriptInterface

interfaceyii\validators\client\ClientValidatorScriptInterface
Since22.0
Sourceframework/validators/client/ClientValidatorScriptInterface.php

Defines the contract for client-side validator script generation.

Classes implementing this interface provide methods for retrieving client-side validation options and registering the corresponding JavaScript code for a given validator, model, and attribute.

MethodDescriptionDefined by
getClientOptions() abstractReturns client-side validation options for the specified validator, model, and attribute.ClientValidatorScriptInterface
register() abstractRegisters the client-side validation script for the specified validator, model, and attribute in the view.ClientValidatorScriptInterface
abstract public function getClientOptions(yii\validators\client\T $validator, yii\base\Model $model, string $attribute): array<string, mixed>

Returns client-side validation options for the specified validator, model, and attribute.

Parameters

ParameterTypeDescription
$validatoryii\validators\client\TThe validator instance.
$modelyii\base\ModelThe data model being validated.
$attributestringThe attribute name being validated.

Returns

array<string, mixed>: Client-side validation options.

abstract public function register(yii\validators\client\T $validator, yii\base\Model $model, string $attribute, yii\web\View $view): string|null

Registers the client-side validation script for the specified validator, model, and attribute in the view.

Parameters

ParameterTypeDescription
$validatoryii\validators\client\TThe validator instance.
$modelyii\base\ModelThe data model being validated.
$attributestringThe attribute name being validated.
$viewyii\web\ViewThe view instance where the script will be registered.

Returns

string|null: The client-side validation script, or null if not supported.