The thing is when i click the link when the page is just refreshed the dialog opens but empty. I then close the dialog and reopen it. The second time (and other nexts) are ok. The form just appear as expected.
I have to say that there are other links in the page using a jquery procedure which is not generated by yii and when the yii generated dialog displays they stop working !!!
I have just seen the ajax click button and it doesnt make any sense the ‘onclick’ option in the ajax. It looks that ajaxLink button has a confusing interpretation of that onclick attribute (http://api.jquery.com/jQuery.ajax/) and I believe is because that the button supposed to make an ajax update call through its onclick.
You have good javascript written, you are actually doing something very similar with what I do in my projects. This is what I recommend you to do:
Forget about your ajaxLink button and create a normal ‘link’ button:
// to display the button link (see the rel attribute?)
CHtml::link(CHtml::image(Yii::app->request->baseUrl.'/img/validate2.png'),'#',array('class'=>'deleteCourse','rel'=>$value['id']));
// the javascript you need to register on the view
// bit modification of your code
$('a.deleteCourse').live('click',function( e ){
// getting the id of the button clicked
var id = $(this).attr('rel');
$("#confcoudel").dialog({
resizable: false,
id:'showConcoudel',
height:'auto',
width:250,
modal: true,
autoOpen:false,
buttons: {
'Delete course': function() {
$.ajax({
type: 'POST',
url:'../student_courses/delete/'+id, // button id
data: "id="+id, // here I place the id of the button
})
$(this).dialog('close');
currentCOURSE.fadeOut('fast');
},
Cancel: function() {
$(this).dialog('close');
}
}
});
// FORGOT TO ADD THIS
e.stopPropagation();
return false;
});
Try it, is untested, but looks a little bit like my solutions
I recommend you that you use Yii to create every single LINK of your code, whether is Javascript or PHP. The url for the AJAX post on your code could give you problem. You could just use Yii::app()->request->createUrl or $this->createUrl from a view.
Many many thanks for your help here. Your smart code helped me solved the problem of the delete button. However, I’m still struggling for the validation button. But now, whatever happens, the delete button works just as it should.
From your code i’ve just changed the autoOpen to true, that’s all.
I’m going to try to solve the validation form issue. If it fails I might get back with a new forum topic.