Hello, thank you for your reply.
I just recreated the error with a new simple CRUD generated by Gii. If you just take the delete button from view.php and put it on update.php it keeps working fine, but if you place it inside _form.php it will ask for double confirmation. It seems the delete javascript is called again after model validation and before actually commiting the delete action.
Ayone has ideas on how to fix this behavior? I’d still like to preserve the “sub-view” _form.php as it is shared between update.php and create.php. Right now the workaround would be to not use _form.php and put it all inside update.php but that’s not optimal… Any ideas are welcome. Thank you!
Button code as generated by gii:
<?= Html::a('Delete', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to delete this item?',
'method' => 'post',
],
]) ?>
Edit: After testing a lot, it seems that the problem happens only when the delete button is placed inside the existing ActiveForm. I didn’t have this problem in Yii 1, where I did this:
CHtml::link('Delete', '#', array(
'class'=>'btn btn-danger',
'submit'=>$this->createUrl('delete', array('id'=>$model->id)),
'confirm'=>'Are you sure you want to delete this item?',
));
I just want to put a simple delete button on the side of the "update" button…
If I put it outside the existing form, it works fine but the button is displayed one line below, and I’d like it to be next to the update button.
Your ideas are appreciated. Thank you.