Modal Removedata

Hi,

After calling modal removedata (add button click), delete button on gridview stop working, here is my code:

index.php


<?php

Yii::app()->clientScript->registerScript('utama', "

$('.modal-footer .btn-primary').on('click',function(){

	$.ajax({

		dataType:'json',

		type: $('#kuri-form').attr('method'),

		url: $('#kuri-form').attr('action'),

		data: $('#kuri-form').serialize(),

		success: function(data) {

			if (data.header=='berhasil') {

				$.fn.yiiGridView.update('jkuliah-grid');	

			}

		}

	});

});	

");

?>

<?php

if (Yii::app()->user->checkAccess('jkuliah.create')) {

	$helpUrl = $this->createUrl('create',array('siswa'=>$siswa));

	echo TbHtml::button('Add', array(

			'color' => TbHtml::BUTTON_COLOR_SUCCESS,

			'onclick'=>"$('#cru-dialog').removeData('modal');										

							$('#cru-dialog').modal({remote:'$helpUrl'});

							$('#cru-dialog').modal('show');",			

			));				

}		

?>

<?php 

$form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(

	'id'=>'jkuliah-form',

	'enableAjaxValidation'=>false,

	'action'=>$this->createUrl('approv',array('siswa'=>$siswa)),

	'htmlOptions'=>array(

		'onsubmit'=>"return false;"),

	));

	

$this->widget('bootstrap.widgets.TbGridView',array(

	'id'=>'jkuliah-grid',

	'type' => 'striped bordered condensed hover',		

	'dataProvider'=>$model->search($siswa),

	'filter'=>$model,

	'columns'=>array(

		array(

			'name' => 'id',

			'id' => 'JurnalId',

			'value' => '$data->primaryKey',

			'selectableRows' => '10',

			'class' => 'CCheckBoxColumn',

			'htmlOptions' => array('width'=>'2%'),

		),	

		array(

			'name'=>'mkuliah',

			'value'=>'$data->mkuliah->nama',

			),

		array(

			'class'=>'bootstrap.widgets.TbButtonColumn',

			'template'=>'{delete}',

			'htmlOptions'=>array('style'=>'text-align:center','width'=>'5%'),		

			'buttons'=>array(

				'delete'=>array('visible'=>"Yii::app()->user->checkAccess('jkuliah.delete')"),

				)				

		),

	),

)); 


$this->endWidget();

?>

<?php

$this->beginWidget('bootstrap.widgets.TbModal', array(

    'id'=>'cru-dialog',

	'header' => 'Mata Kuliah',

	'footer' => array(

			TbHtml::button('Add Selected',array('data-dismiss' => 'modal','class'=>'btn-primary btn-large')),

			TbHtml::button('Close', array('data-dismiss' => 'modal','class'=>'btn-warning btn-large')),	

			),

	'htmlOptions'=>array('style' => 'width: auto; margin-left: -100px;')				

    ));


$this->endWidget();

?>

_kurihlp.php


<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(

'id'=>'kuri-form',

'enableAjaxValidation'=>false,

'htmlOptions'=>array('onsubmit'=>"return false;"),

)); ?>

<?php $this->widget('bootstrap.widgets.TbGridView',array(

	'id'=>'kuri-help',

	'type' => 'striped bordered condensed hover',

	'dataProvider'=>$model->bantu($siswa),

	'filter'=>$model,

	'columns'=>array(

		array(

			'name' => 'id',

			'id' => 'kuriId',

			'value' => '$data->primaryKey',

			'selectableRows' => '10',

			'class' => 'CCheckBoxColumn',

			'htmlOptions' => array('width'=>'5%'),

		),		

		array(

			'name'=>'semester',

			'value'=>'$data->mkuliah->semester',

			'htmlOptions'=>array('width'=>'5%'),

			),					

		array(

			'name'=>'mkuliah',

			'value'=>'$data->mkuliah->nama',

			),

		array(

			'header'=>'Kode',

			'value'=>'$data->mkuliah->kode',

			'htmlOptions'=>array('width'=>'5%'),

			),			

	),

)); ?>

<?php $this->endWidget(); ?>

controller :


<?php


class JkuliahController extends Controller

{

	public function actionDelete($id)

	{

		if (Yii::app()->request->isPostRequest) {

			// we only allow deletion via POST request

			$this->loadModel($id,'Jkuliah')->delete();


			// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser

			if (!isset($_GET['ajax'])) {

				$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));

			}

		} else {

			throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');

		}

	}


	public function actionIndex($siswa)

	{

		$model=new Jkuliah('search');

		$model->unsetAttributes();  // clear any default values

		if (isset($_GET['Jkuliah'])) {

			$model->attributes=$_GET['Jkuliah'];

		}


		$msiswa=$this->loadModel($siswa,'Msiswa');

		

		$this->render('index',array(

			'model'=>$model,

			'siswa'=>$siswa,

			'msiswa'=>$msiswa,

		));

	}


}

what wrong with my code ?

This is too few information to help you. What’s about an error message?

Did you look at the console output for javascript errors or did you set debugger breakpoint at actionDelete() …

See the last two items of the guidelines.

after modal open which removedata call, delete button did not submit post action to server.

delete button work normal again after page has been refresh manually.

Error 400

Your request is invalid.

The error message tells that the delete request is invalid, because of incorrect params -> missing id??

Does it work when you comment the ‘removeData’?

Check the html-source with firebug/chrome and look what happens after ‘removeModal’

Maybe try


$('#cru-dialog').data('modal', null);

instead

when I comment remove data, delete button work normally, but remote modal body not loaded

I try replace removedata with this:


$('#cru-dialog').data('modal', null);

same error

The error message tells that the delete request is invalid, because the delete request was not POST request

If the delete is no POST request, the error message should be ‘Invalid request. Please do not repeat this request again.’ - see your actionDelete() above.

I don’t know, what bootstrap does on ‘removeData’.

If you set a breakpoint with the debugger

  • is the request executed?

  • what’s coming in? $_POST, $_GET …?

When working with ajax calls, a debugger is a MUST have.

This error message from firebug :

TypeError: settings is undefined

http://localhost/kh.../assets/172b2dcd/jquery.js line 564 > eval

Line 252

  • In this case you have a js-error that means, the delete request cannot not be executed (actionDelete)??

  • On the other side you have an ‘Error 400 Your request is invalid.’ that means the actionDelete is called but with wrong params??

Sorry, I have no more ideas…

-> debug, debug js-code - maybe by aler(XY) …