Multiple Widget Creation In One Page

Hi, I have created an widget which is based on https://github.com/gEndelf/jquery.businessHours. The problem is I cannot create two instances of the widget in the same page. This is the call in the view


<?php 

$htmlCode = "<div class='dayContainer'><div data-original-title='' class='colorBox'><input type='checkbox' class='invisible operationState'/></div><div class='weekday'></div>";

$htmlCode = $htmlCode . "<div class='operationDayTimeContainer'>";

$htmlCode = $htmlCode . "<div class='operationTime input-group'><span class='input-group-addon'><i class='fa fa-sun-o'></i></span><input name='startTime' class='mini-time form-control operationTimeFrom' value='' type='text' disabled></div>";


$htmlCode = $htmlCode . "<div class='operationTime input-group'><span class='input-group-addon'><i class='fa fa-moon-o'></i></span><input name='endTime' class='mini-time form-control operationTimeTill' value='' type='text' disabled></div>";

$htmlCode = $htmlCode . "</div></div>";




$this->widget('application.widgets.businessHours.EBusinessHours', array(

		'options' => array(

				'inputDisabled'=>true,

				'checkedColorClass'=> 'workingBusinssDay',

				'uncheckedColorClass'=> 'dayOff',

				'dayTmpl' => $htmlCode,

				'operationTime'=>$availabilityHoursForDisplay

		),

	//	'htmlOptions' => array(

	//			'id'=>'businessHoursContainer',

	//	),

		'id'=>'businessHoursContainer',

));

?>

and this is the widget


class EBusinessHours extends CWidget {

	

//	private $assets;

	public $options=array();

	public $htmlOptions=array();

//	public $id;

	

	const ASSETS_NAME_BUSINESSHOURS='/jquery.businessHours';

	const ASSETS_NAME_TIMEPICKER='/bootstrap-timepicker.min';

	// στο init δίνω τα options και αρχικοποιώ το widget

	public function init() {

	//	$assets = Yii::getPathOfAlias('application.extensions'). DIRECTORY_SEPARATOR.'businessHours'. DIRECTORY_SEPARATOR.'assets';

		if(isset($this->htmlOptions['id']))

			$this->id=$this->htmlOptions['id'];

		else

			$this->htmlOptions['id']=$this->getId();

		

		$this->registerClientScript();

		

	//	$this->baseUrl = Yii::app()->getAssetManager()->publish($assets);

		

		return parent::init();

	}

	

	public function run() {		

		echo CHtml::tag('div',$this->htmlOptions,'');

	}

	

	protected function registerClientScript(){

	//	$assets = Yii::app()->getAssetManager()->publish(dirname(__FILE__).DIRECTORY_SEPARATOR.'assets');

		$assets = Yii::app()->getAssetManager()->publish(dirname(__FILE__).DIRECTORY_SEPARATOR.'assets',false,-1,true);

		

		$cs = Yii::app()->getClientScript();

		$options=CJavaScript::encode($this->options);

		

		$js = "var {$this->getId()} = $('#{$this->getId()}').businessHours($options);";

		$cs->registerScript('availability',$js,CClientScript::POS_END);

				

		$cs->registerCssFile($assets.self::ASSETS_NAME_BUSINESSHOURS.'.css');

		$cs->registerScriptFile($assets.self::ASSETS_NAME_BUSINESSHOURS.'.js',CClientScript::POS_END);

		$cs->registerCssFile($assets.self::ASSETS_NAME_TIMEPICKER.'.css');

		$cs->registerScriptFile($assets.self::ASSETS_NAME_TIMEPICKER.'.js',CClientScript::POS_END);

	}

	

	

}

Try to add the "id" to the registerScript first parameter:


$cs->registerScript('availability_' . $this->getId(), $js, CClientScript::POS_END);

Yes Argent you are right. This caused the problem. Thank you very much. :D