I created active form:
ActiveForm::begin([
'validateOnBlur' => false,
'validateOnChange' => false,
'enableAjaxValidation' => false,
'enableClientValidation'=> false,
'options' => [
'id' => 'emails',
'data' => [
'pjax' => 1
],
'enctype' => 'multipart/form-data'
],
'action' => ['update', 'id' => $model->id]
]) ?>
...some fields...
Html::a(Yii::t('app', 'Delete Message'), ['delete-email', 'id' => $model->id], [
'class' => 'btn btn-primary',
'data' => [
'confirm' => 'Are you sure want to delete this message?',
'method' => 'post',
]
]);
...some fields...
<? ActiveForm::end(); ?>
Simplified:
<? ActiveForm::begin([]) ?>
<?= Html::a('Delete', ['delete-email', 'id' => $model->id], [
'class' => 'btn btn-primary',
'data' => [
'confirm' => 'Are you sure want to delete this message?',
'method' => 'post',
]
]); ?>
<? ActiveForm::end(); ?>
Should see a dialog box with the question.
Two dialog appear one after another.
| Q | A
| ---------------- | ---
| Yii version | 2.0.10
| PHP version | 7.0
| Operating system | Windows 10
Similar problem:
https://github.com/yiisoft/yii2/issues/6642
I think it's better to wait until the tests for yii.activeForm.js
will be written to prevent breaking of something else. I can handle this later.
Hello!
I have the same issue after updating yii2 to 2.0.10.
Found, that the problem is in yii.activeForm.js
and in this line data.submitObject.trigger("click");
var updateInputs = function ($form, messages, submitting) {
...
data.validated = true;
if (data.submitObject) {
data.submitObject.trigger("click");
} else {
$form.submit();
}
...
Also, I want to add, that first click on such tag "a" with data-confirm perform validation of the form inputs and "click" propagation is stopped.
Also, if there was not valid input, you will never succes in the tag "a" "click" - propagation will be stoped.
Also, if some field was valid before first click, you click this "a", and then clear data for the required input, there will be no validation error for this input (form will be validated)!
I can reproduce the issue on 2.0.10, but current master branch seems to work correctly.
@MatthewPattell @TrueZurg @dhimancontact @yupe @alemedinam @bariew could you try your code on master branch? To do it, run composer require "yiisoft/yii2:dev-master"
Waiting for your reports. Thank you in advance
I'm have similar bug. After update yii to "dev-master", confirm dialog became shown 1 times. Thank you!
Then it seems the issue is solved. Thanks for verifying it.
@samdark when will the fix incorporated to stable release? I prefer using stable branch than dev-master. Thanks.
We are going to release 2.0.11 in a week or two
@SilverFire Yii version 2.0.11.2 - problem is still here.
@TrueZurg, same problem? Is info in the ticket enough to reliably reproduce it?
@samdark yes.
Inside ActiveForm I have tag "a" with data-confirn. And if some field has not valid value (for example required filed with empty input) there will be no successful confirmation after tag "a" click. I wrote about it early here. Yii version 2.0.11.2
I haven't tried 2.0.12 yet.
Please try 2.0.12.
@samdark tried 2.0.12 The same effect!
@TrueZurg I've re-checked with code from master and the following snippet:
<? ActiveForm::begin([]) ?>
<?= Html::a('Delete', ['delete-email', 'id' => 'test'], [
'class' => 'btn btn-primary',
'data' => [
'confirm' => 'Are you sure want to delete this message?',
'method' => 'post',
]
]); ?>
<? ActiveForm::end(); ?>
Dialogue appears once.
So your issue may be different from what was reported and fixed in this one. If so, please create a new issue with details on how to reproduce it. Thanks.
Most helpful comment
We are going to release 2.0.11 in a week or two