After partialRender JQuery is not working

Hi @all,

I have a big issue since three days… maybe someone can provide me help.

I have a index.php with some jqueryui controls, ajaxsubmitbutton and a partial render page _result.php which renders a CListView. If I click on the button to request a partial render, the jquery ui controls are not working anymore.

any suggestions? It seems like jquery ui is not loaded.

if I add the RegisterScript of jquery and jquery ui to the partial render page, it seems that jquery is working again. but the controls are in an unknown state. and wont work properly again. but this time without a script error.

My main.php for the script includes:





<?php 

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

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

		

Yii::app()->clientScript->registerCssFile(Yii::app()->clientScript->getCoreScriptUrl().'/jui/css/base/jquery-ui.css');

?>



index.php with some code snippets for the jquery ui radiobuttons


<div id="gametypeRadio" class="rowRadioButtons clearfix" >

<?php 


echo CHtml::radioButtonList('gametype_id', '', $modelGameType, 

				array( 'template'=>"{input}{label}", 'separator' => "",		

					'class' => 'gametyperadiobuttons',

));

?>

</div>

the js code self made for the radio buttons:




/*<![CDATA[*/

		$(document).ready(function() {

			$( "#gametypeRadio" ).buttonset();

			$( "#holztypeRadio" ).buttonset();

			$( "#playersPerTableRadio" ).buttonset();

			$( "#limittypeRadio" ).buttonset();

        });


	jQuery(function($) {

		// update holztype if gametype changes

		jQuery('body').undelegate('.gametyperadiobuttons','click').delegate('.gametyperadiobuttons','click',function(){

				// disable and uncheck other sub radio buttons if gametyp changes

				

				$( "#gametypeRadio" ).buttonset();

				$( "#holztypeRadio" ).buttonset();

				$( "#playersPerTableRadio" ).buttonset();

				$( "#limittypeRadio" ).buttonset();

			

				jQuery('.playerspertableradiobuttons').button( "disable" );

				jQuery('.limittyperadiobuttons').button( "disable" );

				jQuery('.holztyperadiobuttons').button( "disable" );

				

				$('.playerspertableradiobuttons').prop('checked', false);

				$('.limittyperadiobuttons').prop('checked', false);

				$('.holztyperadiobuttons').prop('checked', false);

				

				jQuery('.playerspertableradiobuttons').button( "refresh" );

				jQuery('.limittyperadiobuttons').button( "refresh" );

				jQuery('.holztyperadiobuttons').button( "refresh" );

			

				jQuery.ajax({

					'type':'POST',

					'url':'/holz/index.php/UserSkillConfig/dynamicholzTypesForRadioButtons',

					'cache':false,

					'data':jQuery(this).parents("form").serialize(),

					'success':function(html){

						

						jQuery("#holztypeRadio").html(html);

						$( "#holztypeRadio" ).buttonset();

					}

				});


				return false;

		});



The partial render page _ajaxSearch.php


<?php


$this->widget('zii.widgets.CListView', array(

	    'dataProvider'=>$dataProvider,

		'enablePagination' => false,

	    'itemView'=>'_listview',

	    'id'=>'ajaxListView',

		'ajaxUrl' => CController::createUrl('HolzCoach/dynamicSearchResult')

));

?>

Any Suggestion would be great! :)

Thanks!

Quick reply:

Try setting to true the last parameter of renderPartial() and remove all that registerScript lines.

I didn’t test it.

Hi!

I tested it but it is still not working.

Why should I remove the registerScript?

my ajax action which is triggered by the ajaxsubmitbutton is sending already a true:


    	$dataProvider =  new CActiveDataProvider('UserSkillConfig', array(

	        'pagination'=>array(

	            'pageSize'=>5,

        	),

        	'criteria'=>$criteria,

   		));

   		

   		$data = array();

        $data["dataProvider"] = $dataProvider;

        

   		$this->renderPartial('_ajaxSearch', $data, false, true);

	}

In the index.php I adjusted it. but again it doesnt work…

Any other suggestions?

EDIT:

Which one do you mean?

$return or $processOutput?

If I set the last one to true. in index.php and in my controller I get the an error when trying to set the buttonset().


<?php 

	$this->renderPartial('_ajaxSearch', array('dataProvider'=>$dataProvider), false, true);

	echo CHtml::endForm(); 

?>

ERROR :$("#gametypeRadio").buttonset is not a function

I meant $processOutput because it will register all needed JavaScript needed by that view. And because of that I told you to remove all those registerScript statements, and let Yii do it for you. Take a look at AJAX response to see if there are all resources needed by widget.

Thanks for the description. As I am including jquery.ui for my buttonsets I recognized that the widgets are doing the same. In that case, I have jquery loaded twice. By turning of the jquery loading


        Yii::app()->clientscript->scriptMap['jquery-ui.min.js'] = false;

        Yii::app()->clientscript->scriptMap['jquery.js'] = false;

I solved the issue.