From a32753b5e5844a3a1895377b4bc4828108775cf5 Mon Sep 17 00:00:00 2001 From: Borales Date: Thu, 13 Feb 2014 16:13:22 +0200 Subject: [PATCH 1/3] #2417 Possibility to specify dataType for $.ajax call in yii.activeForm.js --- framework/assets/yii.activeForm.js | 6 ++++-- framework/widgets/ActiveForm.php | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/framework/assets/yii.activeForm.js b/framework/assets/yii.activeForm.js index 92e05b0..d4acc3d 100644 --- a/framework/assets/yii.activeForm.js +++ b/framework/assets/yii.activeForm.js @@ -45,7 +45,9 @@ // function ($form, attribute, messages) afterValidate: undefined, // the GET parameter name indicating an AJAX-based validation - ajaxVar: 'ajax' + ajaxVar: 'ajax', + // the type of data that you're expecting back from the server + ajaxDataType: 'json' }; var attributeDefaults = { @@ -301,7 +303,7 @@ url: data.settings.validationUrl, type: $form.prop('method'), data: $form.serialize() + extData, - dataType: 'json', + dataType: data.settings.ajaxDataType, success: function (msgs) { if (msgs !== null && typeof msgs === 'object') { $.each(data.attributes, function () { diff --git a/framework/widgets/ActiveForm.php b/framework/widgets/ActiveForm.php index caedca7..e7618ca 100644 --- a/framework/widgets/ActiveForm.php +++ b/framework/widgets/ActiveForm.php @@ -104,6 +104,10 @@ class ActiveForm extends Widget */ public $ajaxVar = 'ajax'; /** + * @var string the type of data that you're expecting back from the server. + */ + public $ajaxDataType = 'json'; + /** * @var string|JsExpression a JS callback that will be called when the form is being submitted. * The signature of the callback should be: * @@ -187,6 +191,7 @@ class ActiveForm extends Widget 'successCssClass' => $this->successCssClass, 'validatingCssClass' => $this->validatingCssClass, 'ajaxVar' => $this->ajaxVar, + 'ajaxDataType' => $this->ajaxDataType, ]; if ($this->validationUrl !== null) { $options['validationUrl'] = Html::url($this->validationUrl); From 0a27360cd821db3ac28b835ce928ad4eb65ce7c1 Mon Sep 17 00:00:00 2001 From: Borales Date: Thu, 13 Feb 2014 16:41:27 +0200 Subject: [PATCH 2/3] Adding @since tag and changelog line --- framework/CHANGELOG.md | 1 + framework/widgets/ActiveForm.php | 1 + 2 files changed, 2 insertions(+) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index c8b620a..8019387 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -109,6 +109,7 @@ Yii Framework 2 Change Log - Enh #2240: Improved `yii\web\AssetManager::publish()`, `yii\web\AssetManager::getPublishedPath()` and `yii\web\AssetManager::getPublishedUrl()` to support aliases (vova07) - Enh #2325: Adding support for the `X-HTTP-Method-Override` header in `yii\web\Request::getMethod()` (pawzar) - Enh #2364: Take into account current error reporting level in error handler (gureedo) +- Enh #2417: Added possibility to set `dataType` for `$.ajax` call in yii.activeForm.js (Borales) - Enh: Added support for using arrays as option values for console commands (qiangxue) - Enh: Added `favicon.ico` and `robots.txt` to default application templates (samdark) - Enh: Added `Widget::autoIdPrefix` to support prefixing automatically generated widget IDs (qiangxue) diff --git a/framework/widgets/ActiveForm.php b/framework/widgets/ActiveForm.php index e7618ca..abd0a02 100644 --- a/framework/widgets/ActiveForm.php +++ b/framework/widgets/ActiveForm.php @@ -105,6 +105,7 @@ class ActiveForm extends Widget public $ajaxVar = 'ajax'; /** * @var string the type of data that you're expecting back from the server. + * @since 2.0 */ public $ajaxDataType = 'json'; /** From 36aab9e36cf27c7918f9e04ca25ff4a2c91b5ddf Mon Sep 17 00:00:00 2001 From: Borales Date: Thu, 13 Feb 2014 16:42:08 +0200 Subject: [PATCH 3/3] Removing @since tag --- framework/widgets/ActiveForm.php | 1 - 1 file changed, 1 deletion(-) diff --git a/framework/widgets/ActiveForm.php b/framework/widgets/ActiveForm.php index abd0a02..e7618ca 100644 --- a/framework/widgets/ActiveForm.php +++ b/framework/widgets/ActiveForm.php @@ -105,7 +105,6 @@ class ActiveForm extends Widget public $ajaxVar = 'ajax'; /** * @var string the type of data that you're expecting back from the server. - * @since 2.0 */ public $ajaxDataType = 'json'; /**