Yii Framework Forum: Two Datepicker In Admin - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Two Datepicker In Admin One is blocking the other properties Rate Topic: -----

#1 User is offline   luisp88 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 19-February 13
  • Location:Caracas - Venezuela

Posted 25 February 2013 - 06:25 PM

Hello everyone! hope you doing well

I am having a problem. I have a datepicker to filter in admin view (CGridView)
in the _search.php, I am calling it this way
echo $this->renderPartial('application.views.partials.PSelecFecha', array('model'=>$model,'name'=>'fecha_nacimiento'));


And in the php file, there is the widget
$this->widget('zii.widgets.jui.CJuiDatePicker',
	array('model'=>$model,
		'attribute'=>$name,
		'value'=>$model->$name,
		'language' => 'es',
		'htmlOptions' => array(
			//'readonly'=>"readonly"
		),
		'options'=>array(
			'autoSize'=>false,
			'defaultDate'=>$model->$name,
			'dateFormat'=>'dd-mm-yy',
			'buttonImage'=>Yii::app()->baseUrl.'/images/create_new.gif',
			'buttonImageOnly'=>true,
			'buttonText'=>'Fecha',
			'selectOtherMonths'=>false,
			'showAnim'=>'slide',
			'showButtonPanel'=>false,
			//'showOn'=>'button',
			'showOtherMonths'=>false,
                    
                        'yearRange'=>'-1910',
                    
			'changeMonth' => 'true',
			'changeYear' => 'true',
			'minDate'=>date("d-m-Y",strtotime("1910-01-01")), //fecha minima
		),
	));


and then, in the admin.php, I have
'afterAjaxUpdate' => 'reinstallDatePicker', // (#1)

in the cgridview properties, then at the end, I have

Yii::app()->clientScript->registerScript('re-install-date-picker', "
function reinstallDatePicker(id, data) {
    $('#datepicker_nacimiento').datepicker();
    $.datepicker.setDefaults($.datepicker.regional['es']);
}
");


and for the filter of the grid, I have
array(
                    'name' => 'fecha_nacimiento',
                    'value'=> '$data->fecha_nacimiento',
                    'filter' => $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                        'model'=>$model, 
                        'attribute'=>'fecha_nacimiento',
                        'language' => 'es',
                        'i18nScriptFile' => 'jquery.ui.datepicker-es.js', // (#2)
                        'htmlOptions' => array(
                            'id' => 'datepicker_nacimiento',
                            //'readonly'=>"readonly"
                        ),
                        'defaultOptions' => array(  // (#3)
                            'language' => 'es',
                            //'showOn' => 'focus', 
                            'dateFormat' => 'dd-mm-yy',
                            'yearRange'=>'1960',
                            'minDate'=>date("d-m-Y",strtotime("1960-01-01")), //fecha minima
                            //'minDate'=>'date("Y-m-d")', //fecha minima
                            'maxDate'=>'date("Y-m-d")', //fecha maxima
                            
                            'showOtherMonths' => true,
                            'selectOtherMonths' => true,
                            'changeMonth' => true,
                            'changeYear' => true,
                            //'showButtonPanel' => true,
                        )
                    ), 
                    true), // (#4)
                ),


I think I am doing it wrong because I am having problems with the format and filtering, but when I remove the advanced search form and left just the CGridView filters, it works fine. When there are two date pickers, they both crash!

Is there any simpler way to do it? I mean inserting the datepicker in gridview and _search and dont loosing the format and properties.

Thanks in advanced
0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,082
  • Joined: 16-February 11
  • Location:Japan

Posted 08 March 2013 - 08:43 PM

Hi luisp88,

Would you please try this?
$this->widget('zii.widgets.jui.CJuiDatePicker',
	array('model'=>$model,
		'attribute'=>$name,
//		'value'=>$model->$name,  /* Do not use 'value' */
		'language' => 'es',
		'htmlOptions' => array(
			//'readonly'=>"readonly"
		),
		'options'=>array(
			'autoSize'=>false,
			'defaultDate'=>$model->$name,
			'dateFormat'=>'dd-mm-yy',
			'buttonImage'=>Yii::app()->baseUrl.'/images/create_new.gif',
			'buttonImageOnly'=>true,
			'buttonText'=>'Fecha',
			'selectOtherMonths'=>false,
// 			'showAnim'=>'slide', /* Do not use animation */
			'showButtonPanel'=>false,
			//'showOn'=>'button',
			'showOtherMonths'=>false,
                    
                        'yearRange'=>'-1910',
                    
			'changeMonth' => 'true',
			'changeYear' => 'true',
			'minDate'=>date("d-m-Y",strtotime("1910-01-01")), //fecha minima
		),
	));


1) You should use either "model"-"attribute" pair or "name"-"value" pair. Do not mix them.
2) Do not use animation. It tends to cause problems especially when there are 2 or more date pickers in a page.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users