/**
  * @inheritdoc
  */
 public function clientValidateAttribute($model, $attribute, $view)
 {
     $pattern = Html::escapeJsRegularExpression($this->pattern);
     $options = ['pattern' => new JsExpression($pattern), 'not' => $this->not, 'message' => Leaps::$app->getI18n()->format($this->message, ['attribute' => $model->getAttributeLabel($attribute)], Leaps::$app->language)];
     if ($this->skipOnEmpty) {
         $options['skipOnEmpty'] = 1;
     }
     ValidationAsset::register($view);
     return 'leaps.validation.regularExpression(value, messages, ' . Json::htmlEncode($options) . ');';
 }
Exemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function clientValidateAttribute($model, $attribute, $view)
 {
     if ($this->filter !== 'trim') {
         return null;
     }
     $options = [];
     if ($this->skipOnEmpty) {
         $options['skipOnEmpty'] = 1;
     }
     ValidationAsset::register($view);
     return 'value = leaps.validation.trim($form, attribute, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');';
 }
Exemplo n.º 3
0
 /**
  * @inheritdoc
  */
 public function clientValidateAttribute($model, $attribute, $view)
 {
     $options = ['trueValue' => $this->trueValue, 'falseValue' => $this->falseValue, 'message' => Leaps::$app->getI18n()->format($this->message, ['attribute' => $model->getAttributeLabel($attribute), 'true' => $this->trueValue, 'false' => $this->falseValue], Leaps::$app->language)];
     if ($this->skipOnEmpty) {
         $options['skipOnEmpty'] = 1;
     }
     if ($this->strict) {
         $options['strict'] = 1;
     }
     ValidationAsset::register($view);
     return 'leaps.validation.boolean(value, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');';
 }
Exemplo n.º 4
0
 /**
  * @inheritdoc
  */
 public function clientValidateAttribute($model, $attribute, $view)
 {
     $options = [];
     if ($this->requiredValue !== null) {
         $options['message'] = Leaps::$app->getI18n()->format($this->message, ['requiredValue' => $this->requiredValue], Leaps::$app->language);
         $options['requiredValue'] = $this->requiredValue;
     } else {
         $options['message'] = $this->message;
     }
     if ($this->strict) {
         $options['strict'] = 1;
     }
     $options['message'] = Leaps::$app->getI18n()->format($options['message'], ['attribute' => $model->getAttributeLabel($attribute)], Leaps::$app->language);
     ValidationAsset::register($view);
     return 'leaps.validation.required(value, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');';
 }
Exemplo n.º 5
0
 /**
  * @inheritdoc
  */
 public function clientValidateAttribute($model, $attribute, $view)
 {
     ValidationAsset::register($view);
     $options = $this->getClientOptions($model, $attribute);
     return 'leaps.validation.image(attribute, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ', deferred);';
 }
Exemplo n.º 6
0
 /**
  * @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' => Leaps::$app->getI18n()->format($this->message, ['attribute' => $model->getAttributeLabel($attribute)], Leaps::$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 'leaps.validation.url(value, messages, ' . Json::htmlEncode($options) . ');';
 }
Exemplo n.º 7
0
 /**
  * @inheritdoc
  */
 public function clientValidateAttribute($model, $attribute, $view)
 {
     $label = $model->getAttributeLabel($attribute);
     $options = ['message' => Leaps::$app->getI18n()->format($this->message, ['attribute' => $label], Leaps::$app->language)];
     if ($this->min !== null) {
         $options['min'] = $this->min;
         $options['tooShort'] = Leaps::$app->getI18n()->format($this->tooShort, ['attribute' => $label, 'min' => $this->min], Leaps::$app->language);
     }
     if ($this->max !== null) {
         $options['max'] = $this->max;
         $options['tooLong'] = Leaps::$app->getI18n()->format($this->tooLong, ['attribute' => $label, 'max' => $this->max], Leaps::$app->language);
     }
     if ($this->length !== null) {
         $options['is'] = $this->length;
         $options['notEqual'] = Leaps::$app->getI18n()->format($this->notEqual, ['attribute' => $label, 'length' => $this->length], Leaps::$app->language);
     }
     if ($this->skipOnEmpty) {
         $options['skipOnEmpty'] = 1;
     }
     ValidationAsset::register($view);
     return 'leaps.validation.string(value, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');';
 }
Exemplo n.º 8
0
 /**
  * @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' => 'leapsCaptcha/' . $this->captchaAction, 'caseSensitive' => $this->caseSensitive, 'message' => Leaps::$app->getI18n()->format($this->message, ['attribute' => $object->getAttributeLabel($attribute)], Leaps::$app->language)];
     if ($this->skipOnEmpty) {
         $options['skipOnEmpty'] = 1;
     }
     ValidationAsset::register($view);
     return 'leaps.validation.captcha(value, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');';
 }
Exemplo n.º 9
0
 /**
  * @inheritdoc
  */
 public function clientValidateAttribute($model, $attribute, $view)
 {
     $label = $model->getAttributeLabel($attribute);
     $options = ['pattern' => new JsExpression($this->integerOnly ? $this->integerPattern : $this->numberPattern), 'message' => Leaps::$app->getI18n()->format($this->message, ['attribute' => $label], Leaps::$app->language)];
     if ($this->min !== null) {
         $options['min'] = is_string($this->min) ? (double) $this->min : $this->min;
         $options['tooSmall'] = Leaps::$app->getI18n()->format($this->tooSmall, ['attribute' => $label, 'min' => $this->min], Leaps::$app->language);
     }
     if ($this->max !== null) {
         $options['max'] = is_string($this->max) ? (double) $this->max : $this->max;
         $options['tooBig'] = Leaps::$app->getI18n()->format($this->tooBig, ['attribute' => $label, 'max' => $this->max], Leaps::$app->language);
     }
     if ($this->skipOnEmpty) {
         $options['skipOnEmpty'] = 1;
     }
     ValidationAsset::register($view);
     return 'leaps.validation.number(value, messages, ' . Json::htmlEncode($options) . ');';
 }
Exemplo n.º 10
0
 /**
  * @inheritdoc
  */
 public function clientValidateAttribute($model, $attribute, $view)
 {
     $options = ['pattern' => new JsExpression($this->pattern), 'fullPattern' => new JsExpression($this->fullPattern), 'allowName' => $this->allowName, 'message' => Leaps::$app->getI18n()->format($this->message, ['attribute' => $model->getAttributeLabel($attribute)], Leaps::$app->language), 'enableIDN' => (bool) $this->enableIDN];
     if ($this->skipOnEmpty) {
         $options['skipOnEmpty'] = 1;
     }
     ValidationAsset::register($view);
     if ($this->enableIDN) {
         PunycodeAsset::register($view);
     }
     return 'leaps.validation.email(value, messages, ' . Json::htmlEncode($options) . ');';
 }
Exemplo n.º 11
0
 /**
  * @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'] = Leaps::$app->getI18n()->format($this->message, ['attribute' => $model->getAttributeLabel($attribute), 'compareAttribute' => $compareValue, 'compareValue' => $compareValue], Leaps::$app->language);
     ValidationAsset::register($view);
     return 'leaps.validation.compare(value, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');';
 }
Exemplo n.º 12
0
 /**
  * @inheritdoc
  */
 public function clientValidateAttribute($model, $attribute, $view)
 {
     $range = [];
     foreach ($this->range as $value) {
         $range[] = (string) $value;
     }
     $options = ['range' => $range, 'not' => $this->not, 'message' => Leaps::$app->getI18n()->format($this->message, ['attribute' => $model->getAttributeLabel($attribute)], Leaps::$app->language)];
     if ($this->skipOnEmpty) {
         $options['skipOnEmpty'] = 1;
     }
     if ($this->allowArray) {
         $options['allowArray'] = 1;
     }
     ValidationAsset::register($view);
     return 'leaps.validation.range(value, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');';
 }