开发者

Using ZendX_JQuery_Form_Element_DatePicker to find the current Server Time

开发者 https://www.devze.com 2023-02-08 11:22 出处:网络
Iam using ZendX_JQuery_Form_Element_DatePicker, I want to set the a default date to the date time picker.

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_DatePicke开发者_如何学JAVAr('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.


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.


Try using Zend_Date()

so the line would look like

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

Hope that helps!


Try

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

Instead of

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号