本文整理汇总了PHP中yii\validators\ValidationAsset类的典型用法代码示例。如果您正苦于以下问题:PHP ValidationAsset类的具体用法?PHP ValidationAsset怎么用?PHP ValidationAsset使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ValidationAsset类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: clientValidateAttribute
/**
* @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) . ');';
}
示例2: clientValidateAttribute
/**
* @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) . ');';
}
示例3: clientValidateAttribute
/**
* @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) . ');';
}
示例4: clientValidateAttribute
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) . ');';
}
示例5: clientValidateAttribute
/**
* @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) . ');';
}
示例6: clientValidateAttribute
/**
* @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) . ');';
}
示例7: clientValidateAttribute
/**
* @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) . ');';
}
示例8: clientValidateAttribute
/**
* @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) . ');';
}
示例9: clientValidateAttribute
/**
* @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) . ');';
}
示例10: clientValidateAttribute
/**
* @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) . ');';
}
示例11: clientValidateAttribute
/**
* @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) . ');';
}
示例12: clientValidateAttribute
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);
}
示例13: clientValidateAttribute
/**
* @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);';
}
示例14: clientValidateAttribute
/**
* @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) . ');';
}
示例15: clientValidateAttribute
/**
* @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) . ');';
}