From 5d016ddf1e9b645b0545ef820ad1e0f7cbebd7f6 Mon Sep 17 00:00:00 2001 From: wkf928592 Date: Mon, 14 Mar 2016 17:16:58 +0800 Subject: [PATCH] add client validation --- src/PhoneInputValidator.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/PhoneInputValidator.php b/src/PhoneInputValidator.php index 8058fc6..bd435d3 100644 --- a/src/PhoneInputValidator.php +++ b/src/PhoneInputValidator.php @@ -5,6 +5,8 @@ use libphonenumber\NumberParseException; use libphonenumber\PhoneNumberUtil; use yii\validators\Validator; +use yii\helpers\Html; +use yii\helpers\Json; /** * Validates the given attribute value with the PhoneNumberUtil library. @@ -37,4 +39,27 @@ protected function validateValue($value) } return $valid ? null : [$this->message, []]; } -} \ No newline at end of file + + /** + * @inheritdoc + */ + public function clientValidateAttribute($model, $attribute, $view) { + + $telInputId = Html::getInputId($model, $attribute); + $options = Json::htmlEncode([ + 'message' => Yii::$app->getI18n()->format($this->message, [ + 'attribute' => $model->getAttributeLabel($attribute) + ], Yii::$app->language) + ]); + + return <<