Two Confirmations While Trying To Delete An Item

Hello.

I’ve got a CRUD interface for one table. Deleting the item from the list view succeeds. Confirmation pops out and everything goes fine. It’s not default zii.CListView, but regular table:

<!-- views/vlan/list.php -->


echo CHtml::link('<i class="icon-remove3"></i>', '#',

	array(

		'submit'  => Y::url("/network/vlan/del", array("id" => $vlan->id)),

		'confirm' => "Are you sure you want to delete VLAN {$vlan-caption}?",

		'id'      => 'delete'.$vlan->id,

		'class'   => 'btn btn-link btn-icon btn-xs',

		'title'   => 'Delete',

	)

);

<!-- controllers/VlanController.php -->


public function actionDel($id) {

	try {

		Vlan::model()->findByPk($id)->delete();

		Yii::app()->user->setFlash('info', "VLAN $id successfully deleted");

	} catch(Exception $e) {

		Yii::app()->user->setFlash('danger', "Unable to delete VLAN $id");

		$this->redirect( Y::url('/network/vlan') );

	}

	$this->redirect( Y::url('/network/vlan') );

}

But if I’m trying to delete the item from edit interface, i’ve got two confirmations in a row:

<!-- views/vlan/form.php -->


if( $this->action->Id == 'edit' ) {

	echo CHtml::button('Delete',

		array(

			'submit'  => Y::url("/network/vlan/del", array("id" => $model->id)),

			'confirm' => "Are you sure you want to delete this VLAN?",

			'id'      => 'delete'.$model->id,

			'class'   => 'btn btn-danger',

		)

	);

}

echo CHtml::submitButton('Save', array('class'=>'btn btn-primary'));

I’ve found the same thing on the second CRUD module, so it’s kinda systematic.

I tried to debug the JavaScript and found, that:

  • Page is not being reloaded after the first confirmation

  • submitForm() from jquery.yii.js is being called twice. As if $(f).trigger(‘submit’) fails on a first attempt.

  • I replaced it with




$(f).submit(function(e){

alert('test');

e.preventDefault();

});

but no alert shows up. I tried to "step in" in the debugger, but sank in the depths of jQuery.

  • I disabled all custom scripts. No success.

I’d appreciate any advice how to deal with this weird behavior or any kind of workaround.

Yii: 1.1.14

jQuery: 1.8.3 (framework default) or 1.10.1 (custom mapped)

UPDATE1:

To exclude an issue with custom template and scripting, I’ve created a blank ‘webapp’ with basic functionality. There’s still two confirmations even for trivial application built from scratch for single table without any relations.

UPDATE2: SOLUTION

The issue was with form declaration.

The form with problem was declarated like:


$form = $this->beginWidget('CActiveForm',array(

	'focus'                => array($model, 'id'),

	'enableAjaxValidation' => true,

	'clientOptions'        => array(

		'validateOnSubmit' => true

	),

	'htmlOptions'          => array(

		'class' => 'form-horizontal',

		'role'  => 'form'

	),

));



Everything was fine before deleting current item from this page. The correct declaration must not contain validateOnSubmit:


$form = $this->beginWidget('CActiveForm',array(

	'focus'                => array($model, 'id'),

	'enableAjaxValidation' => true,

	'htmlOptions'          => array(

		'class' => 'form-horizontal',

		'role'  => 'form'

	),

));



This is lack of deep understanding of form options and framework mechanics.

I simply love submitting the questions on forum and finding answer myself after a coffee break <_<