Commit d445ab9d by Alexander Makarov

Merge pull request #2418 from yiiframework-com-ua/2417-active-form-ajax-data-type

PullRequest for #2417
parents f53863d7 36aab9e3
...@@ -109,6 +109,7 @@ Yii Framework 2 Change Log ...@@ -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 #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 #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 #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 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 `favicon.ico` and `robots.txt` to default application templates (samdark)
- Enh: Added `Widget::autoIdPrefix` to support prefixing automatically generated widget IDs (qiangxue) - Enh: Added `Widget::autoIdPrefix` to support prefixing automatically generated widget IDs (qiangxue)
......
...@@ -45,7 +45,9 @@ ...@@ -45,7 +45,9 @@
// function ($form, attribute, messages) // function ($form, attribute, messages)
afterValidate: undefined, afterValidate: undefined,
// the GET parameter name indicating an AJAX-based validation // 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 = { var attributeDefaults = {
...@@ -301,7 +303,7 @@ ...@@ -301,7 +303,7 @@
url: data.settings.validationUrl, url: data.settings.validationUrl,
type: $form.prop('method'), type: $form.prop('method'),
data: $form.serialize() + extData, data: $form.serialize() + extData,
dataType: 'json', dataType: data.settings.ajaxDataType,
success: function (msgs) { success: function (msgs) {
if (msgs !== null && typeof msgs === 'object') { if (msgs !== null && typeof msgs === 'object') {
$.each(data.attributes, function () { $.each(data.attributes, function () {
......
...@@ -104,6 +104,10 @@ class ActiveForm extends Widget ...@@ -104,6 +104,10 @@ class ActiveForm extends Widget
*/ */
public $ajaxVar = 'ajax'; 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. * @var string|JsExpression a JS callback that will be called when the form is being submitted.
* The signature of the callback should be: * The signature of the callback should be:
* *
...@@ -187,6 +191,7 @@ class ActiveForm extends Widget ...@@ -187,6 +191,7 @@ class ActiveForm extends Widget
'successCssClass' => $this->successCssClass, 'successCssClass' => $this->successCssClass,
'validatingCssClass' => $this->validatingCssClass, 'validatingCssClass' => $this->validatingCssClass,
'ajaxVar' => $this->ajaxVar, 'ajaxVar' => $this->ajaxVar,
'ajaxDataType' => $this->ajaxDataType,
]; ];
if ($this->validationUrl !== null) { if ($this->validationUrl !== null) {
$options['validationUrl'] = Html::url($this->validationUrl); $options['validationUrl'] = Html::url($this->validationUrl);
......
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