YiiBooster icon indicating copy to clipboard operation
YiiBooster copied to clipboard

DatePicker changeDate event handler

Open DGEAPerez opened this issue 10 years ago • 0 comments

I wrotte this:

...
$opcionesDatePicker = array(
    'wrapperHtmlOptions' => array(
        'class' => 'col-xl-2',
    ),
    'widgetOptions' => array(
        'options' => array(
            'format' => 'yyyy-mm-dd',
            'viewformat' => 'dd-mm-yyyy',
            'language' => 'es',
            'autoclose' => true,
            'startDate' => $model->inicio,
            'endDate' => $model->fin,
            'beforeShowDay' => "js:function(date){return EstiloFeriado(date, 'ob', fListaFeriados)}",
            'changeDate' => 'js:cambiaFecha()',
        ),
    ),
    'prepend' => '<i class="glyphicon glyphicon-calendar"></i>',
);
...
echo $form->datePickerGroup($model, 'fFecha', $opcionesDatePicker);
...

And it render this: (indented to easy reading)

jQuery('#Horarios_fFecha').datepicker({
  'format':'yyyy-mm-dd',
  'viewformat':'dd-mm-yyyy',
  'language':'es',
  'autoclose':true,
  'startDate':'2013-09-02',
  'endDate':'2014-06-30',
  'beforeShowDay':function(date){return EstiloFeriado(date, 'ob', fListaFeriados)},
  'changeDate':cambiaFecha()
});

In this way, cambiaFecha only is runned when the document is created, but never when a date is picked in the control...

A workaround I find is:

Yii::app()->getClientScript()->registerScript("fixed", // un ID unico tambien
        "$('#Horarios_fFecha').datepicker()
          .on('changeDate', function(e){
        cambiaFecha(e);
    });", CClientScript::POS_LOAD);

How is the right way to do that without the workaround?

DGEAPerez avatar Aug 06 '14 19:08 DGEAPerez