renderPartial and registerScript Issue

Hello Everyone,

After reading lots of post on forum, Still i didn’t get a proper solution for it.

Well,i am facing a common issue with a renderPartial and registerScript on my project :(

I have a page on which i am calling some action with Ajax call and they are rendering a partial view.And my partial view contain some forms and tabs.Which are not displaying properly.Tabs are not displaying properly. and ajax forms in that partial view are also not displaying.

But i have some tabs also on the page and they are working fine.So,the issue is After Ajax call tabs are not working and also ajax forms are not working.

So, what i want is after renderPartial view my tabs are ajax forms should work perfectly.

This what i have done in my layout file




Yii::app()->clientScript->registerCoreScript('jquery');

Yii::app()->clientScript->registerCoreScript('jquery.ui');



And this is my Action code in controller file.




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

			$this->renderPartial("view_name",array(),false,true);

		}else {

            throw new CHttpException(400, 'Invalid request. You are trying to access this comment for which you are not permitted.');

		}



I have already tried the solution provided for this common problem.But still its not working for me.It would be great if anybody can tell me what wrong i am doing here.

Thanks and Regards,

jayant

Hi jayant,

http://www.stilbruch.at/2011/06/yii-when-yii-fucks-with-you-loading.html

Um, the linked article is not very modest in its style, full of 4 letter words ;D

But I hope it’s useful to you.

Jayant,

I see the logic and from your statement

What is not clear to me is whether you having this code within the same action for both post and ajax (I suspect, this may be the case) or separate action for your post? In other words are you calling something like, if ajax request, renderPartial(…) and in the same action render() for normal post?

Remember that calling both ajax and post has to call an action…

If you have them both within the same action, then the behaviour you are having should be expected. When you make an ajax request, then calling renderPartial is executed, so there is no way to get back to the action. Do you see what I’m getting at?

How are you making your ajax call?

What responses are you getting from your firebug or chrome console?

I ask these question to better understand your su=ituation or even getting you to see your challenge in a different perspective

Also if you do find a solution, do please post it back to help the community tackle these kinds of problems

Hey softark,

Thanks for your response. But still it doesn’t work for me. :(

Hey seal,

Thanks for your response.I’ll try to check my code again and will get back to this post.

thanks again.

Hello

Don’t you want to post your codes?

Cheers :)

Hey bennouna,

Thanks for showing your interest in my problem. Well i come to know that this issue is not related to Yii.Since i was trying mu code with HTM: and PHP files then same problem is occurring.So, it means its not related to yii its related to Jquery UI tabs and Ajax response. :(

But still i can’t figure it out whats wrong with it.If you can help me here then it would be great help for me.:)

i have attached my code in zip file in which i have also added an image which is a problem.When i am clicking on Manage role link from left section then ajax response update the same section as it is showing now in right section.Which contain Jquery UI tabs.

So, the problem is When i click on manange role link then in ajax response Jquery UI tabs are not loading.

All the ajax call are mention in common.js file.

Let it try if you can dig into it.Waiting for your kind response.:)

Thanks and Regards,

jayant

I hope the following changes in common.js should solve the problem in your posted program.




//this function is written to remove Html and Call different Overlay

function changeSection(){

	//$('.right_panel').html('<img src ="'+imagePath+'ajax-loader.gif" class="loaderSection">');

	$.ajax({

		url:"test.php",

		// async: false,

		cache: false,

		dataType:'html',

		success:function(data){

			if (data != "") {

				$('.right_panel').html(data);	

				$('#tabs').tabs();

				$('#tabs1').tabs();

				$('#tabs2').tabs();

			}

		}

	});

}



$(’#tabs’), $(’#tabs1’) and $(’#tabs2’) has been converted into tabs in the initial load. The spacial attributes added by Jui scripts will make them look and behave like tabs.

But those elements will be updated by ajax, because they all belong to $(‘right_panel’), and will return to plain html elements. They will loose the special attributes added by Jui scripts.

So, we convert them into tabs once again after the successful ajax update.

Thanks softark,

Thank you for your help.i have done also same thing and its working now. :) but one issue is still remaining and one more query i have in my mind.

  1. There is a Horizontal expand feature also.Which initiate on the click of arrow image.But its not working after ajax call.:(

  2. i would like to know from you that does my these form will be work fine with Model validation in Yii.Since i am not sure about Model validation.But regarding a submitting these forms, i can do it :) but want to know regarding my queries.

Waiting for your response.

  1. Use jquery.on() instead of jquery.click().



    $('body').on('click', '#controlbtn', function(e) {

        ...



jquery.on() is a real savior in many ajax problems.

The element that holds the event handler should be outside of the content that will be updated by ajax. I used ‘body’ in this example, but it is not always necessary to use ‘body’.

And you can specify the element to trigger the event (’#controlbtn’) as the 2nd parameter.

http://api.jquery.com/on/

  1. Yes, it should work. Use CActiveForm widget to make things easy.

But if you mean ajax validation, like on-the-fly inline error messages, I guess you will need some trick to re-activate the functionality after the form is updated by ajax.

  1. Yupp sure, you are right.After doing some google i got this.So, i am going to use it. thanks for your help. :)

  2. Yes, i know i have to use CActiveForm but a model validation is quite tricky part here ;)

Anyways thanks for your Quick responses. :)