2

Iam using ZendX_JQuery_Form_Element_DatePicker, I want to set the a default date to the date time picker.

My current code is this -

$date = new ZendX_JQuery_Form_Element_DatePicker('date',
                array('jQueryParams' => array('defaultDate' => date('Y-m-D'),
                                'changeYear'=> 'true')));
        $date->setJQueryParam('dateFormat', 'dd.mm.yy')
                ->setRequired()
                ->setLabel("Date");

This returns the date as August 2016 on the calender. Iam not sure what am doing wrong. Can someone suggest here the code for getting the correct server date.

Charles
  • 50,943
  • 13
  • 104
  • 142
Sumit Ghosh
  • 3,264
  • 4
  • 40
  • 59

3 Answers3

5

I would recommend considering using JQuery without ZendX_JQuery (if possible). The reason is that currently there is discussion about Discontinuing Maintenance of ZendX JQuery - Suggest drop for 2.0.

If you do not use ZendX_JQuery, then the default date could be set during construction of your Zend_From. For example:

 $dateInput = $this->createElement('text', 'date');
 $dateInput->addValidator(new Zend_Validate_Date(array('format' => 'dd.MM.yyyy')));
 $dateInput->setValue(Zend_Date::now()->toString('dd.MM.yyyy'));

Then in your view, you could add:

<script language="JavaScript">
    // assummmig date text input field has id="date"
    // datepicker automatically will set itself to the current value in the field
    // dateFormat seems different, but this is because there are some differences
    // between formats in Zend_Data and JQuery.
    $( "#date" ).datepicker({ dateFormat: 'dd.mm.yy' });
</script>

Nevertheless, returning to your code I think the defaultDate should be in the current dateFormat (from datepicker doc). In your code, it is not, so this may be one reason it does not work properly.

Marcin
  • 215,873
  • 14
  • 235
  • 294
0

Try using Zend_Date()

so the line would look like

 array('jQueryParams' => array('defaultDate' => new Zend_Date(),

Hope that helps!

ehudokai
  • 1,928
  • 12
  • 9
0

Try

array('defaultDate' => date('d-m-y')

Instead of

array('defaultDate' => date('Y-m-D')

sudol
  • 207
  • 3
  • 10