/** * @inheritdoc */ public function clientValidateAttribute($model, $attribute, $view) { if ($this->filter !== 'trim') { return null; } ValidationAsset::register($view); $options = $this->getClientOptions($model, $attribute); return 'value = yii.validation.trim($form, attribute, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');'; }
/** * @inheritdoc */ public function clientValidateAttribute($model, $attribute, $view) { $pattern = Html::escapeJsRegularExpression($this->pattern); $options = ['pattern' => new JsExpression($pattern), 'not' => $this->not, 'message' => Yii::$app->getI18n()->format($this->message, ['attribute' => $model->getAttributeLabel($attribute)], Yii::$app->language)]; if ($this->skipOnEmpty) { $options['skipOnEmpty'] = 1; } ValidationAsset::register($view); return 'yii.validation.regularExpression(value, messages, ' . Json::htmlEncode($options) . ');'; }
/** * @inheritdoc */ public function clientValidateAttribute($model, $attribute, $view) { $this->ensureEnum($model, $attribute); $options = ['range' => array_map('strval', array_keys($this->enum)), 'not' => false, 'message' => Yii::$app->getI18n()->format($this->message, ['attribute' => $model->getAttributeLabel($attribute)], Yii::$app->language)]; if ($this->skipOnEmpty) { $options['skipOnEmpty'] = 1; } ValidationAsset::register($view); return 'yii.validation.range(value, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');'; }
public function clientValidateAttribute($object, $attribute, $view) { $captcha = $this->createCaptchaAction(); $code = $captcha->getVerifyCode(false); $hash = $captcha->generateValidationHash($this->caseSensitive ? $code : mb_strtolower($code)); $options = ['hash' => $hash, 'hashKey' => 'yiiCaptcha/' . $this->captchaAction, 'caseSensitive' => $this->caseSensitive, 'message' => Yii::$app->getI18n()->format($this->message, ['attribute' => $object->getAttributeLabel($attribute)], Yii::$app->language)]; if ($this->skipOnEmpty) { $options['skipOnEmpty'] = 1; } ValidationAsset::register($view); return 'yii.validation.captcha(value, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');'; }
/** * @inheritdoc */ public function clientValidateAttribute($model, $attribute, $view) { $options = ['trueValue' => $this->trueValue, 'falseValue' => $this->falseValue, 'message' => Yii::$app->getI18n()->format($this->message, ['attribute' => $model->getAttributeLabel($attribute), 'true' => $this->trueValue === true ? 'true' : $this->trueValue, 'false' => $this->falseValue === false ? 'false' : $this->falseValue], Yii::$app->language)]; if ($this->skipOnEmpty) { $options['skipOnEmpty'] = 1; } if ($this->strict) { $options['strict'] = 1; } ValidationAsset::register($view); return 'yii.validation.boolean(value, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');'; }
/** * @inheritdoc */ public function clientValidateAttribute($object, $attribute, $view) { $options = ['trueValue' => $this->trueValue, 'falseValue' => $this->falseValue, 'message' => Yii::$app->getI18n()->format($this->message, ['attribute' => $object->getAttributeLabel($attribute), 'true' => $this->trueValue, 'false' => $this->falseValue], Yii::$app->language)]; if ($this->skipOnEmpty) { $options['skipOnEmpty'] = 1; } if ($this->strict) { $options['strict'] = 1; } ValidationAsset::register($view); return 'yii.validation.boolean(value, messages, ' . json_encode($options) . ');'; }
/** * @inheritdoc */ public function clientValidateAttribute($model, $attribute, $view) { if ($this->filter !== 'trim') { return null; } $options = []; if ($this->skipOnEmpty) { $options['skipOnEmpty'] = 1; } ValidationAsset::register($view); return 'yii.validation.trim($form, attribute, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');'; }
/** * @inheritdoc */ public function clientValidateAttribute($object, $attribute, $view) { $range = []; foreach ($this->range as $value) { $range[] = (string) $value; } $options = ['range' => $range, 'not' => $this->not, 'message' => Yii::$app->getI18n()->format($this->message, ['attribute' => $object->getAttributeLabel($attribute)], Yii::$app->language)]; if ($this->skipOnEmpty) { $options['skipOnEmpty'] = 1; } ValidationAsset::register($view); return 'yii.validation.range(value, messages, ' . json_encode($options) . ');'; }
/** * @inheritdoc */ public function clientValidateAttribute($model, $attribute, $view) { $options = ['operator' => $this->operator, 'type' => $this->type]; if ($this->compareValue !== null) { $options['compareValue'] = $this->compareValue; $compareValue = $this->compareValue; } else { $compareAttribute = $this->compareAttribute === null ? $attribute . '_repeat' : $this->compareAttribute; $compareValue = $model->getAttributeLabel($compareAttribute); $options['compareAttribute'] = Html::getInputId($model, $compareAttribute); } if ($this->skipOnEmpty) { $options['skipOnEmpty'] = 1; } $options['message'] = Yii::$app->getI18n()->format($this->message, ['attribute' => $model->getAttributeLabel($attribute), 'compareAttribute' => $compareValue, 'compareValue' => $compareValue], Yii::$app->language); ValidationAsset::register($view); return 'yii.validation.compare(attribute, value, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');'; }
/** * @inheritdoc */ public function clientValidateAttribute($model, $attribute, $view) { $options = []; if ($this->requiredValue !== null) { $options['message'] = Yii::$app->getI18n()->format($this->message, ['requiredValue' => $this->requiredValue], Yii::$app->language); $options['requiredValue'] = $this->requiredValue; } else { $options['message'] = $this->message; } if ($this->strict) { $options['strict'] = 1; } $options['message'] = Yii::$app->getI18n()->format($options['message'], ['attribute' => $model->getAttributeLabel($attribute)], Yii::$app->language); ValidationAsset::register($view); $id = Html::getInputId($model, $attribute); // TODO require validation return ' yii.validation.required(UE.getEditor("' . $id . '").getContent(), messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');'; }
/** * @inheritdoc */ public function clientValidateAttribute($object, $attribute, $view) { $pattern = $this->pattern; //$pattern = preg_replace('/\\\\x\{?([0-9a-fA-F]+)\}?/', '\u$1', $pattern); $deliminator = substr($pattern, 0, 1); $pos = strrpos($pattern, $deliminator, 1); $flag = substr($pattern, $pos + 1); if ($deliminator !== '/') { $pattern = '/' . str_replace('/', '\\/', substr($pattern, 1, $pos - 1)) . '/'; } else { $pattern = substr($pattern, 0, $pos + 1); } if (!empty($flag)) { $pattern .= preg_replace('/[^igm]/', '', $flag); } $options = ['pattern' => new JsExpression($pattern), 'not' => $this->not, 'message' => Yii::$app->getI18n()->format($this->message, ['attribute' => $object->getAttributeLabel($attribute)], Yii::$app->language)]; if ($this->skipOnEmpty) { $options['skipOnEmpty'] = 1; } ValidationAsset::register($view); return 'yii.validation.regularExpression(value, messages, ' . Json::encode($options) . ');'; }
public function clientValidateAttribute($model, $attribute, $view) { $className = explode('\\', $model->className()); $className = strtolower(end($className)); $formName = strtolower($model->formName()); $label = $model->getAttributeLabel($attribute); $options = ['message' => Yii::$app->getI18n()->format($this->message, ['attribute' => $label], Yii::$app->language)]; $formName = strtolower($model->formName()); $options = Json::htmlEncode($options); ValidationAsset::register($view); $view->registerJs(<<<JS (function(){\t\t\t\t var telInput = \$("#{$formName}-{$attribute}"); if (!telInput.intlTelInput('isValidNumber')) { \tmessages.push({$options}.message); } \t\tvar intlNumber = telInput.intlTelInput("getNumber"); \t\ttelInput.value = intlNumber; \t\t \t\tdocument.getElementById("{$className}-{$attribute}").value = intlNumber; \t\tdocument.getElementById("{$className}-{$attribute}").disabled = false; \t\t \t\t//var countryData = \$.fn.intlTelInput.getCountryData(); \t\t//console.log(countryData); })(); JS , \yii\web\View::POS_LOAD); // $view->registerJs(<<<JS // (function(){ // var telInput = $('#$formName-$attribute'); // if (!telInput.intlTelInput('isValidNumber')) { // messages.push($options.message); // } // })(); // JS // , \yii\web\View::POS_LOAD); }
/** * @inheritdoc */ public function clientValidateAttribute($model, $attribute, $view) { ValidationAsset::register($view); $options = $this->getClientOptions($model, $attribute); return 'yii.validation.image(attribute, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ', deferred);'; }
/** * @inheritdoc */ public function clientValidateAttribute($model, $attribute, $view) { $options = ['pattern' => new JsExpression($this->pattern), 'fullPattern' => new JsExpression($this->fullPattern), 'allowName' => $this->allowName, 'message' => Yii::$app->getI18n()->format($this->message, ['attribute' => $model->getAttributeLabel($attribute)], Yii::$app->language), 'enableIDN' => (bool) $this->enableIDN]; if ($this->skipOnEmpty) { $options['skipOnEmpty'] = 1; } ValidationAsset::register($view); if ($this->enableIDN) { PunycodeAsset::register($view); } return 'yii.validation.email(value, messages, ' . Json::htmlEncode($options) . ');'; }
/** * @inheritdoc */ public function clientValidateAttribute($model, $attribute, $view) { $messages = ['ipv6NotAllowed' => $this->ipv6NotAllowed, 'ipv4NotAllowed' => $this->ipv4NotAllowed, 'message' => $this->message, 'noSubnet' => $this->noSubnet, 'hasSubnet' => $this->hasSubnet]; foreach ($messages as &$message) { $message = Yii::$app->getI18n()->format($message, ['attribute' => $model->getAttributeLabel($attribute)], Yii::$app->language); } $options = ['ipv4Pattern' => new JsExpression(Html::escapeJsRegularExpression($this->ipv4Pattern)), 'ipv6Pattern' => new JsExpression(Html::escapeJsRegularExpression($this->ipv6Pattern)), 'messages' => $messages, 'ipv4' => (bool) $this->ipv4, 'ipv6' => (bool) $this->ipv6, 'ipParsePattern' => new JsExpression(Html::escapeJsRegularExpression($this->getIpParsePattern())), 'negation' => $this->negation, 'subnet' => $this->subnet]; if ($this->skipOnEmpty) { $options['skipOnEmpty'] = 1; } ValidationAsset::register($view); return 'yii.validation.ip(value, messages, ' . Json::htmlEncode($options) . ');'; }
/** * @inheritdoc */ public function clientValidateAttribute($model, $attribute, $view) { if ($this->range instanceof \Closure) { $this->range = call_user_func($this->range, $model, $attribute); } $range = []; foreach ($this->range as $value) { $range[] = (string) $value; } $options = ['range' => $range, 'not' => $this->not, 'message' => Yii::$app->getI18n()->format($this->message, ['attribute' => $model->getAttributeLabel($attribute)], Yii::$app->language)]; if ($this->skipOnEmpty) { $options['skipOnEmpty'] = 1; } if ($this->allowArray) { $options['allowArray'] = 1; } ValidationAsset::register($view); return 'yii.validation.range(value, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');'; }
/** * @inheritdoc */ public function clientValidateAttribute($model, $attribute, $view) { if ($this->range instanceof \Closure) { $this->range = call_user_func($this->range, $model, $attribute); } ValidationAsset::register($view); $options = $this->getClientOptions($model, $attribute); return 'yii.validation.range(value, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');'; }
/** * @inheritdoc */ public function clientValidateAttribute($model, $attribute, $view) { ValidationAsset::register($view); if ($this->enableIDN) { PunycodeAsset::register($view); } $options = $this->getClientOptions($model, $attribute); return 'yii.validation.email(value, messages, ' . Json::htmlEncode($options) . ');'; }
/** * @inheritdoc */ public function clientValidateAttribute($model, $attribute, $view) { if (strpos($this->pattern, '{schemes}') !== false) { $pattern = str_replace('{schemes}', '(' . implode('|', $this->validSchemes) . ')', $this->pattern); } else { $pattern = $this->pattern; } $options = ['pattern' => new JsExpression($pattern), 'message' => Yii::$app->getI18n()->format($this->message, ['attribute' => $model->getAttributeLabel($attribute)], Yii::$app->language), 'enableIDN' => (bool) $this->enableIDN]; if ($this->skipOnEmpty) { $options['skipOnEmpty'] = 1; } if ($this->defaultScheme !== null) { $options['defaultScheme'] = $this->defaultScheme; } ValidationAsset::register($view); if ($this->enableIDN) { PunycodeAsset::register($view); } return 'yii.validation.url(value, messages, ' . Json::encode($options) . ');'; }
/** * @inheritdoc */ public function clientValidateAttribute($model, $attribute, $view) { $options = []; if ($this->skipOnEmpty) { $options['skipOnEmpty'] = 1; } if ($this->stripSpaceBeforeComma) { $options['stripSpaceBeforeComma'] = 1; } if ($this->stripSpaceAfterComma) { $options['stripSpaceAfterComma'] = 1; } ValidationAsset::register($view); return 'value = localAppValidation.nocrlf($form, attribute, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');'; }
public function clientValidateAttribute($model, $attribute, $view) { ValidationAsset::register($view); AppValidationAsset::register($view); return 'value = yii.validation.trim($form, attribute, []);' . 'value = mybriop.validation.toLower($form, attribute);'; }
/** * @inheritdoc */ public function clientValidateAttribute($model, $attribute, $view) { $label = $model->getAttributeLabel($attribute); $options = ['message' => Yii::$app->getI18n()->format($this->message, ['attribute' => $label], Yii::$app->language)]; if ($this->min !== null) { $options['min'] = $this->min; $options['tooShort'] = Yii::$app->getI18n()->format($this->tooShort, ['attribute' => $label, 'min' => $this->min], Yii::$app->language); } if ($this->max !== null) { $options['max'] = $this->max; $options['tooLong'] = Yii::$app->getI18n()->format($this->tooLong, ['attribute' => $label, 'max' => $this->max], Yii::$app->language); } if ($this->length !== null) { $options['is'] = $this->length; $options['notEqual'] = Yii::$app->getI18n()->format($this->notEqual, ['attribute' => $label, 'length' => $this->length], Yii::$app->language); } if ($this->skipOnEmpty) { $options['skipOnEmpty'] = 1; } ValidationAsset::register($view); return 'yii.validation.string(value, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');'; }
/** * @inheritdoc */ public function clientValidateAttribute($object, $attribute, $view) { ValidationAsset::register($view); $options = $this->getClientOptions($object, $attribute); return 'yii.validation.file(attribute, messages, ' . json_encode($options) . ');'; }
<?php use common\components\DataInformer; use yii\helpers\Html; use yii\helpers\Url; use yii\widgets\Menu; use yii\widgets\ActiveForm; use roman444uk\magnificPopup\MagnificPopup; use common\models\Advert; $isGuest = Yii::$app->user->isGuest; $actionId = Yii::$app->controller->action->id; $dataInformer = Yii::$app->dataInformer; $isLoginMenuItemVisible = $isGuest && !in_array($actionId, ['registration', 'login']); if ($isLoginMenuItemVisible) { \yii\validators\ValidationAsset::register($this); \yii\widgets\ActiveFormAsset::register($this); } ?> <div id="block-header"> <!-- Choose language section --> <!--<div class="lang-choose"> <?php echo Html::a(Yii::t('app', 'rus'), '', ['class' => "selected"]); ?> <span>|</span> <?php echo Html::a(Yii::t('app', 'ukr')); ?> </div>-->
/** * @inheritdoc */ public function clientValidateAttribute($object, $attribute, $view) { $options = []; if ($this->requiredValue !== null) { $options['message'] = Yii::$app->getI18n()->format($this->message, ['requiredValue' => $this->requiredValue], Yii::$app->language); $options['requiredValue'] = $this->requiredValue; } else { $options['message'] = $this->message; } if ($this->strict) { $options['strict'] = 1; } $options['message'] = Yii::$app->getI18n()->format($options['message'], ['attribute' => $object->getAttributeLabel($attribute)], Yii::$app->language); ValidationAsset::register($view); return 'yii.validation.required(value, messages, ' . json_encode($options) . ');'; }
/** * @inheritdoc */ public function clientValidateAttribute($model, $attribute, $view) { $pattern = Html::escapeJsRegularExpression($this->pattern); $options = ['pattern' => new JsExpression($pattern), 'not' => $this->not]; if ($this->skipOnEmpty) { $options['skipOnEmpty'] = 1; } $pattern = Html::escapeJsRegularExpression($this->patternOnPass); $optionsPass = ['pattern' => new JsExpression($pattern), 'not' => $this->notOnPass, 'message' => Yii::$app->getI18n()->format($this->messageOnPass, ['attribute' => $model->getAttributeLabel($attribute)], Yii::$app->language)]; if ($this->skipOnEmpty) { $optionsPass['skipOnEmpty'] = 1; } if ($this->patternOnFail === false) { $optionsFail = false; } else { $pattern = Html::escapeJsRegularExpression($this->patternOnFail); $optionsFail = ['pattern' => new JsExpression($pattern), 'not' => $this->notOnFail, 'message' => Yii::$app->getI18n()->format($this->messageOnFail, ['attribute' => $model->getAttributeLabel($attribute)], Yii::$app->language)]; if ($this->skipOnEmpty) { $optionsFail['skipOnEmpty'] = 1; } } ValidationAsset::register($view); return 'localAppValidation.conditionalRegExp(value, messages, ' . Json::htmlEncode($options) . ', ' . Json::htmlEncode($optionsPass) . ', ' . Json::htmlEncode($optionsFail) . ');'; }
/** * @inheritdoc */ public function clientValidateAttribute($object, $attribute, $view) { $label = $object->getAttributeLabel($attribute); $options = ['pattern' => new JsExpression($this->integerOnly ? $this->integerPattern : $this->numberPattern), 'message' => Yii::$app->getI18n()->format($this->message, ['attribute' => $label], Yii::$app->language)]; if ($this->min !== null) { // ensure numeric value to make javascript comparison equal to PHP comparison // https://github.com/yiisoft/yii2/issues/3118 $options['min'] = is_string($this->min) ? (double) $this->min : $this->min; $options['tooSmall'] = Yii::$app->getI18n()->format($this->tooSmall, ['attribute' => $label, 'min' => $this->min], Yii::$app->language); } if ($this->max !== null) { // ensure numeric value to make javascript comparison equal to PHP comparison // https://github.com/yiisoft/yii2/issues/3118 $options['max'] = is_string($this->max) ? (double) $this->max : $this->max; $options['tooBig'] = Yii::$app->getI18n()->format($this->tooBig, ['attribute' => $label, 'max' => $this->max], Yii::$app->language); } if ($this->skipOnEmpty) { $options['skipOnEmpty'] = 1; } ValidationAsset::register($view); return 'yii.validation.number(value, messages, ' . Json::encode($options) . ');'; }
/** * @inheritdoc */ public function clientValidateAttribute($object, $attribute, $view) { $label = $object->getAttributeLabel($attribute); $options = ['pattern' => new JsExpression($this->integerOnly ? $this->integerPattern : $this->numberPattern), 'message' => Yii::$app->getI18n()->format($this->message, ['attribute' => $label], Yii::$app->language)]; if ($this->min !== null) { $options['min'] = $this->min; $options['tooSmall'] = Yii::$app->getI18n()->format($this->tooSmall, ['attribute' => $label, 'min' => $this->min], Yii::$app->language); } if ($this->max !== null) { $options['max'] = $this->max; $options['tooBig'] = Yii::$app->getI18n()->format($this->tooBig, ['attribute' => $label, 'max' => $this->max], Yii::$app->language); } if ($this->skipOnEmpty) { $options['skipOnEmpty'] = 1; } ValidationAsset::register($view); return 'yii.validation.number(value, messages, ' . Json::encode($options) . ');'; }
/** * @inheritdoc */ public function clientValidateAttribute($object, $attribute, $view) { $captcha = $this->createCaptchaAction(); $code = $captcha->getVerifyCode(false); $hash = $captcha->generateValidationHash($this->caseSensitive ? $code : strtolower($code)); $options = ['hash' => $hash, 'hashKey' => 'yiiCaptcha/' . $this->captchaAction, 'caseSensitive' => $this->caseSensitive, 'message' => strtr($this->message, ['attribute' => $object->getAttributeLabel($attribute)])]; if ($this->skipOnEmpty) { $options['skipOnEmpty'] = 1; } ValidationAsset::register($view); return 'yii.validation.captcha(value, messages, ' . json_encode($options) . ');'; }
/** * @inheritdoc */ public function clientValidateAttribute($model, $attribute, $view) { ValidationAsset::register($view); $options = $this->getClientOptions($model, $attribute); return 'yii.validation.ip(value, messages, ' . Json::htmlEncode($options) . ');'; }