mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-20 16:38:22 +08:00
support form submission by pjax.
This commit is contained in:
@@ -50,9 +50,15 @@ class Pjax extends Widget
|
|||||||
/**
|
/**
|
||||||
* @var string the jQuery selector of the links that should trigger pjax requests.
|
* @var string the jQuery selector of the links that should trigger pjax requests.
|
||||||
* If not set, all links within the enclosed content of Pjax will trigger pjax requests.
|
* If not set, all links within the enclosed content of Pjax will trigger pjax requests.
|
||||||
* Note that the pjax response to a link is a full page, a normal request will be sent again.
|
* Note that if the response to the pjax request is a full page, a normal request will be sent again.
|
||||||
*/
|
*/
|
||||||
public $linkSelector;
|
public $linkSelector;
|
||||||
|
/**
|
||||||
|
* @var string the jQuery selector of the forms whose submissions should trigger pjax requests.
|
||||||
|
* If not set, all forms with `data-pjax` attribute within the enclosed content of Pjax will trigger pjax requests.
|
||||||
|
* Note that if the response to the pjax request is a full page, a normal request will be sent again.
|
||||||
|
*/
|
||||||
|
public $formSelector;
|
||||||
/**
|
/**
|
||||||
* @var boolean whether to enable push state.
|
* @var boolean whether to enable push state.
|
||||||
*/
|
*/
|
||||||
@@ -148,9 +154,11 @@ class Pjax extends Widget
|
|||||||
$this->clientOptions['timeout'] = $this->timeout;
|
$this->clientOptions['timeout'] = $this->timeout;
|
||||||
$options = Json::encode($this->clientOptions);
|
$options = Json::encode($this->clientOptions);
|
||||||
$linkSelector = Json::encode($this->linkSelector !== null ? $this->linkSelector : '#' . $id . ' a');
|
$linkSelector = Json::encode($this->linkSelector !== null ? $this->linkSelector : '#' . $id . ' a');
|
||||||
|
$formSelector = Json::encode($this->formSelector !== null ? $this->formSelector : '#' . $id . ' form[data-pjax]');
|
||||||
$view = $this->getView();
|
$view = $this->getView();
|
||||||
PjaxAsset::register($view);
|
PjaxAsset::register($view);
|
||||||
$js = "jQuery(document).pjax($linkSelector, \"#$id\", $options);";
|
$js = "jQuery(document).pjax($linkSelector, \"#$id\", $options);";
|
||||||
|
$js .= "jQuery(document).on('submit', $formSelector, function (event) {jQuery.pjax.submit(event, '#$id');});";
|
||||||
$view->registerJs($js);
|
$view->registerJs($js);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user