yii\validators\Validator::clientValidateAttribute PHP Method

clientValidateAttribute() public method

You may override this method to return the JavaScript validation code if the validator can support client-side validation. The following JavaScript variables are predefined and can be used in the validation code: - attribute: an object describing the the attribute being validated. - value: the value being validated. - messages: an array used to hold the validation error messages for the attribute. - deferred: an array used to hold deferred objects for asynchronous validation - $form: a jQuery object containing the form element The attribute object contains the following properties: - id: a unique ID identifying the attribute (e.g. "loginform-username") in the form - name: attribute name or expression (e.g. "[0]content" for tabular input) - container: the jQuery selector of the container of the input field - input: the jQuery selector of the input field under the context of the form - error: the jQuery selector of the error tag under the context of the container - status: status of the input field, 0: empty, not entered before, 1: validated, 2: pending validation, 3: validating
See also: yii\widgets\ActiveForm::enableClientValidation
public clientValidateAttribute ( Model $model, string $attribute, View $view ) : string
$model yii\base\Model the data model being validated
$attribute string the name of the attribute to be validated.
$view yii\web\View the view object that is going to be used to render views or view files containing a model form with this validator applied.
return string the client-side validation script. Null if the validator does not support client-side validation.
    public function clientValidateAttribute($model, $attribute, $view)
    {
        return null;
    }

Usage Example

 /**
  * @inheritdoc
  */
 public function clientValidateAttribute($model, $attribute, $view)
 {
     return parent::clientValidateAttribute($model, $attribute, $view);
 }