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 ...@@ -102,6 +102,7 @@ class BooleanValidator extends Validator
$options['strict'] = 1; $options['strict'] = 1;
} }
$view->registerAssetBundle('yii/form');
return 'yii.validation.boolean(value, messages, ' . json_encode($options) . ');'; return 'yii.validation.boolean(value, messages, ' . json_encode($options) . ');';
} }
} }
...@@ -113,6 +113,7 @@ class CaptchaValidator extends Validator ...@@ -113,6 +113,7 @@ class CaptchaValidator extends Validator
$options['skipOnEmpty'] = 1; $options['skipOnEmpty'] = 1;
} }
$view->registerAssetBundle('yii/form');
return 'yii.validation.captcha(value, messages, ' . json_encode($options) . ');'; return 'yii.validation.captcha(value, messages, ' . json_encode($options) . ');';
} }
} }
......
...@@ -205,6 +205,7 @@ class CompareValidator extends Validator ...@@ -205,6 +205,7 @@ class CompareValidator extends Validator
'{compareValue}' => $compareValue, '{compareValue}' => $compareValue,
))); )));
$view->registerAssetBundle('yii/form');
return 'yii.validation.compare(value, messages, ' . json_encode($options) . ');'; return 'yii.validation.compare(value, messages, ' . json_encode($options) . ');';
} }
} }
...@@ -119,10 +119,6 @@ class EmailValidator extends Validator ...@@ -119,10 +119,6 @@ class EmailValidator extends Validator
*/ */
public function clientValidateAttribute($object, $attribute, $view) public function clientValidateAttribute($object, $attribute, $view)
{ {
if ($this->enableIDN) {
$view->registerAssetBundle('punycode');
}
$options = array( $options = array(
'pattern' => new JsExpression($this->pattern), 'pattern' => new JsExpression($this->pattern),
'fullPattern' => new JsExpression($this->fullPattern), 'fullPattern' => new JsExpression($this->fullPattern),
...@@ -137,6 +133,10 @@ class EmailValidator extends Validator ...@@ -137,6 +133,10 @@ class EmailValidator extends Validator
$options['skipOnEmpty'] = 1; $options['skipOnEmpty'] = 1;
} }
$view->registerAssetBundle('yii/form');
if ($this->enableIDN) {
$view->registerAssetBundle('punycode');
}
return 'yii.validation.email(value, messages, ' . Json::encode($options) . ');'; return 'yii.validation.email(value, messages, ' . Json::encode($options) . ');';
} }
} }
...@@ -151,6 +151,7 @@ class NumberValidator extends Validator ...@@ -151,6 +151,7 @@ class NumberValidator extends Validator
$options['skipOnEmpty'] = 1; $options['skipOnEmpty'] = 1;
} }
$view->registerAssetBundle('yii/form');
return 'yii.validation.number(value, messages, ' . Json::encode($options) . ');'; return 'yii.validation.number(value, messages, ' . Json::encode($options) . ');';
} }
} }
...@@ -103,6 +103,7 @@ class RangeValidator extends Validator ...@@ -103,6 +103,7 @@ class RangeValidator extends Validator
$options['skipOnEmpty'] = 1; $options['skipOnEmpty'] = 1;
} }
$view->registerAssetBundle('yii/form');
return 'yii.validation.range(value, messages, ' . json_encode($options) . ');'; return 'yii.validation.range(value, messages, ' . json_encode($options) . ');';
} }
} }
...@@ -112,6 +112,7 @@ class RegularExpressionValidator extends Validator ...@@ -112,6 +112,7 @@ class RegularExpressionValidator extends Validator
$options['skipOnEmpty'] = 1; $options['skipOnEmpty'] = 1;
} }
$view->registerAssetBundle('yii/form');
return 'yii.validation.regularExpression(value, messages, ' . Json::encode($options) . ');'; return 'yii.validation.regularExpression(value, messages, ' . Json::encode($options) . ');';
} }
} }
...@@ -126,6 +126,7 @@ class RequiredValidator extends Validator ...@@ -126,6 +126,7 @@ class RequiredValidator extends Validator
'{value}' => $object->$attribute, '{value}' => $object->$attribute,
))); )));
$view->registerAssetBundle('yii/form');
return 'yii.validation.required(value, messages, ' . json_encode($options) . ');'; return 'yii.validation.required(value, messages, ' . json_encode($options) . ');';
} }
} }
...@@ -170,6 +170,7 @@ class StringValidator extends Validator ...@@ -170,6 +170,7 @@ class StringValidator extends Validator
$options['skipOnEmpty'] = 1; $options['skipOnEmpty'] = 1;
} }
$view->registerAssetBundle('yii/form');
return 'yii.validation.string(value, messages, ' . json_encode($options) . ');'; return 'yii.validation.string(value, messages, ' . json_encode($options) . ');';
} }
} }
......
...@@ -117,10 +117,6 @@ class UrlValidator extends Validator ...@@ -117,10 +117,6 @@ class UrlValidator extends Validator
*/ */
public function clientValidateAttribute($object, $attribute, $view) public function clientValidateAttribute($object, $attribute, $view)
{ {
if ($this->enableIDN) {
$view->registerAssetBundle('punycode');
}
if (strpos($this->pattern, '{schemes}') !== false) { if (strpos($this->pattern, '{schemes}') !== false) {
$pattern = str_replace('{schemes}', '(' . implode('|', $this->validSchemes) . ')', $this->pattern); $pattern = str_replace('{schemes}', '(' . implode('|', $this->validSchemes) . ')', $this->pattern);
} else { } else {
...@@ -142,6 +138,10 @@ class UrlValidator extends Validator ...@@ -142,6 +138,10 @@ class UrlValidator extends Validator
$options['defaultScheme'] = $this->defaultScheme; $options['defaultScheme'] = $this->defaultScheme;
} }
$view->registerAssetBundle('yii/form');
if ($this->enableIDN) {
$view->registerAssetBundle('punycode');
}
return 'yii.validation.url(value, messages, ' . Json::encode($options) . ');'; return 'yii.validation.url(value, messages, ' . Json::encode($options) . ');';
} }
} }
...@@ -134,7 +134,6 @@ class ActiveForm extends Widget ...@@ -134,7 +134,6 @@ class ActiveForm extends Widget
$id = $this->options['id']; $id = $this->options['id'];
$options = Json::encode($this->getClientOptions()); $options = Json::encode($this->getClientOptions());
$attributes = Json::encode($this->attributes); $attributes = Json::encode($this->attributes);
$this->view->registerAssetBundle('yii/form');
$this->view->registerJs("jQuery('#$id').yiiActiveForm($attributes, $options);"); $this->view->registerJs("jQuery('#$id').yiiActiveForm($attributes, $options);");
} }
echo Html::endForm(); 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