Skip to content

Commit 8799a08

Browse files
author
Iuri Jacob
committed
Prevent event duplication when AjaxSubmitButton is loaded through ajax multiple times.
1 parent 00a41eb commit 8799a08

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

AjaxSubmitButton.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ protected function registerAjaxScript()
122122
$this->ajaxOptions['data'] = new JsExpression('$(this).parents("form").serialize()');
123123

124124
$this->ajaxOptions= Json::encode($this->ajaxOptions);
125-
$view->registerJs("$('#".$this->options['id']."').click(function() {
125+
$view->registerJs("$('#".$this->options['id']."').unbind('click').click(function() {
126126
" . (null !== $this->clickedButtonVarName ? "var {$this->clickedButtonVarName} = this;" : "") . "
127127
$.ajax(" . $this->ajaxOptions . ");
128128
return false;
@@ -147,7 +147,7 @@ protected function registerAjaxFormScript()
147147
$this->ajaxOptions= Json::encode($this->ajaxOptions);
148148

149149
$js = <<<SEL
150-
$(document).on('beforeSubmit', "#{$this->useWithActiveForm}", function () {
150+
$(document).unbind('beforeSubmit').on('beforeSubmit', "#{$this->useWithActiveForm}", function () {
151151
if ($(this).find('.has-error').length < 1) {
152152
$.ajax({$this->ajaxOptions});
153153
}

0 commit comments

Comments
 (0)