/**
  * @inheritdoc
  */
 public function getClientOptions($model, $attribute)
 {
     $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;
     }
     return $options;
 }
 /**
  * @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) . ');';
 }
Esempio n. 3
0
 /**
  * @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) . ');';
 }
Esempio n. 4
0
 /**
  * @inheritdoc
  */
 public function getClientOptions($model, $attribute)
 {
     $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;
     }
     return $options;
 }
Esempio n. 5
0
 /**
  * @inheritdoc
  */
 public function getClientOptions($model, $attribute)
 {
     $label = $model->getAttributeLabel($attribute);
     $options = [];
     if ($this->message !== null) {
         $options['message'] = Yii::$app->getI18n()->format($this->message, ['attribute' => $label], Yii::$app->language);
     }
     $options['skipOnEmpty'] = $this->skipOnEmpty;
     if (!$this->skipOnEmpty) {
         $options['uploadRequired'] = Yii::$app->getI18n()->format($this->uploadRequired, ['attribute' => $label], Yii::$app->language);
     }
     if ($this->mimeTypes !== null) {
         $mimeTypes = [];
         foreach ($this->mimeTypes as $mimeType) {
             $mimeTypes[] = new JsExpression(Html::escapeJsRegularExpression($this->buildMimeTypeRegexp($mimeType)));
         }
         $options['mimeTypes'] = $mimeTypes;
         $options['wrongMimeType'] = Yii::$app->getI18n()->format($this->wrongMimeType, ['attribute' => $label, 'mimeTypes' => implode(', ', $this->mimeTypes)], Yii::$app->language);
     }
     if ($this->extensions !== null) {
         $options['extensions'] = $this->extensions;
         $options['wrongExtension'] = Yii::$app->getI18n()->format($this->wrongExtension, ['attribute' => $label, 'extensions' => implode(', ', $this->extensions)], Yii::$app->language);
     }
     if ($this->minSize !== null) {
         $options['minSize'] = $this->minSize;
         $options['tooSmall'] = Yii::$app->getI18n()->format($this->tooSmall, ['attribute' => $label, 'limit' => $this->minSize, 'formattedLimit' => Yii::$app->formatter->asShortSize($this->minSize)], Yii::$app->language);
     }
     if ($this->maxSize !== null) {
         $options['maxSize'] = $this->maxSize;
         $options['tooBig'] = Yii::$app->getI18n()->format($this->tooBig, ['attribute' => $label, 'limit' => $this->getSizeLimit(), 'formattedLimit' => Yii::$app->formatter->asShortSize($this->getSizeLimit())], Yii::$app->language);
     }
     if ($this->maxFiles !== null) {
         $options['maxFiles'] = $this->maxFiles;
         $options['tooMany'] = Yii::$app->getI18n()->format($this->tooMany, ['attribute' => $label, 'limit' => $this->maxFiles], Yii::$app->language);
     }
     return $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) . ');';
 }