Commit d3f2010e by Qiang Xue

Fixes #2380: Added `yii\widgets\ActiveForm::enableClientScript` to support…

Fixes #2380: Added `yii\widgets\ActiveForm::enableClientScript` to support turning on and off client side script generation
parent 93496bf8
......@@ -112,6 +112,7 @@ Yii Framework 2 Change Log
- Enh #1452: Added `Module::getInstance()` to allow accessing the module instance from anywhere within the module (qiangxue)
- Enh #2264: `CookieCollection::has()` will return false for expired or removed cookies (qiangxue)
- Enh #2315: Any operator now could be used with `yii\db\Query::->where()` operand format (samdark)
- Ehn #2380: Added `yii\widgets\ActiveForm::enableClientScript` to support turning on and off client side script generation (qiangxue)
- Enh #2435: `yii\db\IntegrityException` is now thrown on database integrity errors instead of general `yii\db\Exception` (samdark)
- Enh #2558: Enhanced support for memcached by adding `yii\caching\MemCache::persistentId` and `yii\caching\MemCache::options` (qiangxue)
- Enh #2837: Error page now shows arguments in stack trace method calls (samdark)
......@@ -233,7 +234,6 @@ Yii Framework 2 Change Log
- `yii\base\Formatter` functionality has been merged into `yii\i18n\Formatter`
- removed the `yii\base\Formatter` class
- Chg #1551: Refactored DateValidator to support ICU date format and use the format defined in Formatter by default (cebe)
- Chg #2380: `yii\widgets\ActiveForm` will register validation js even if there are not fields inside (qiangxue)
- Chg #2898: `yii\console\controllers\AssetController` is now using hashes instead of timestamps (samdark)
- Chg #2913: RBAC `DbManager` is now initialized via migration (samdark)
- Chg #2914: `ActiveForm::fieldConfig` will be merged recursively with the `$options` parameter in `ActiveForm::field()` (qiangxue)
......
......@@ -105,6 +105,13 @@ class ActiveForm extends Widget
*/
public $enableAjaxValidation = false;
/**
* @var boolean whether to hook up yii.activeForm JavaScript plugin.
* This property must be set true if you want to support client validation and/or AJAX validation, or if you
* want to take advantage of the yii.activeForm plugin. When this is false, the form will not generate
* any JavaScript.
*/
public $enableClientScript = true;
/**
* @var array|string the URL for performing AJAX-based validation. This property will be processed by
* [[Url::to()]]. Please refer to [[Url::to()]] for more details on how to configure this property.
* If this property is not set, it will take the value of the form's action attribute.
......@@ -179,12 +186,14 @@ class ActiveForm extends Widget
throw new InvalidCallException('Each beginField() should have a matching endField() call.');
}
$id = $this->options['id'];
$options = Json::encode($this->getClientOptions());
$attributes = Json::encode($this->attributes);
$view = $this->getView();
ActiveFormAsset::register($view);
$view->registerJs("jQuery('#$id').yiiActiveForm($attributes, $options);");
if ($this->enableClientScript) {
$id = $this->options['id'];
$options = Json::encode($this->getClientOptions());
$attributes = Json::encode($this->attributes);
$view = $this->getView();
ActiveFormAsset::register($view);
$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