Commit bf1b2d99 by resurtm

Form asset bundle registering code moved from ActiveForm::run() to the…

Form asset bundle registering code moved from ActiveForm::run() to the *Validator::clientValidateAttribute().
parent f7b8595f
......@@ -102,6 +102,7 @@ class BooleanValidator extends Validator
$options['strict'] = 1;
}
$view->registerAssetBundle('yii/form');
return 'yii.validation.boolean(value, messages, ' . json_encode($options) . ');';
}
}
......@@ -113,6 +113,7 @@ class CaptchaValidator extends Validator
$options['skipOnEmpty'] = 1;
}
$view->registerAssetBundle('yii/form');
return 'yii.validation.captcha(value, messages, ' . json_encode($options) . ');';
}
}
......
......@@ -205,6 +205,7 @@ class CompareValidator extends Validator
'{compareValue}' => $compareValue,
)));
$view->registerAssetBundle('yii/form');
return 'yii.validation.compare(value, messages, ' . json_encode($options) . ');';
}
}
......@@ -119,10 +119,6 @@ class EmailValidator extends Validator
*/
public function clientValidateAttribute($object, $attribute, $view)
{
if ($this->enableIDN) {
$view->registerAssetBundle('punycode');
}
$options = array(
'pattern' => new JsExpression($this->pattern),
'fullPattern' => new JsExpression($this->fullPattern),
......@@ -137,6 +133,10 @@ class EmailValidator extends Validator
$options['skipOnEmpty'] = 1;
}
$view->registerAssetBundle('yii/form');
if ($this->enableIDN) {
$view->registerAssetBundle('punycode');
}
return 'yii.validation.email(value, messages, ' . Json::encode($options) . ');';
}
}
......@@ -151,6 +151,7 @@ class NumberValidator extends Validator
$options['skipOnEmpty'] = 1;
}
$view->registerAssetBundle('yii/form');
return 'yii.validation.number(value, messages, ' . Json::encode($options) . ');';
}
}
......@@ -103,6 +103,7 @@ class RangeValidator extends Validator
$options['skipOnEmpty'] = 1;
}
$view->registerAssetBundle('yii/form');
return 'yii.validation.range(value, messages, ' . json_encode($options) . ');';
}
}
......@@ -112,6 +112,7 @@ class RegularExpressionValidator extends Validator
$options['skipOnEmpty'] = 1;
}
$view->registerAssetBundle('yii/form');
return 'yii.validation.regularExpression(value, messages, ' . Json::encode($options) . ');';
}
}
......@@ -126,6 +126,7 @@ class RequiredValidator extends Validator
'{value}' => $object->$attribute,
)));
$view->registerAssetBundle('yii/form');
return 'yii.validation.required(value, messages, ' . json_encode($options) . ');';
}
}
......@@ -170,6 +170,7 @@ class StringValidator extends Validator
$options['skipOnEmpty'] = 1;
}
$view->registerAssetBundle('yii/form');
return 'yii.validation.string(value, messages, ' . json_encode($options) . ');';
}
}
......
......@@ -117,10 +117,6 @@ class UrlValidator extends Validator
*/
public function clientValidateAttribute($object, $attribute, $view)
{
if ($this->enableIDN) {
$view->registerAssetBundle('punycode');
}
if (strpos($this->pattern, '{schemes}') !== false) {
$pattern = str_replace('{schemes}', '(' . implode('|', $this->validSchemes) . ')', $this->pattern);
} else {
......@@ -142,6 +138,10 @@ class UrlValidator extends Validator
$options['defaultScheme'] = $this->defaultScheme;
}
$view->registerAssetBundle('yii/form');
if ($this->enableIDN) {
$view->registerAssetBundle('punycode');
}
return 'yii.validation.url(value, messages, ' . Json::encode($options) . ');';
}
}
......@@ -134,7 +134,6 @@ class ActiveForm extends Widget
$id = $this->options['id'];
$options = Json::encode($this->getClientOptions());
$attributes = Json::encode($this->attributes);
$this->view->registerAssetBundle('yii/form');
$this->view->registerJs("jQuery('#$id').yiiActiveForm($attributes, $options);");
}
echo Html::endForm();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment