Domanda

I am using Zendx Jquery to implement the datapicker. I need to disable certain dates, I can do this the manual way of adding the JS to the layout html page but Zendx renders it on the page for you.

The code below works when adding the JS to the layout page:

var unavailableDates = [
new Date(2012, 1, 20).valueOf(),
new Date(2012, 1, 27).valueOf()
];

function unavailable(date) {
if (date.getDay() === 1 && $.inArray(date.valueOf(), unavailableDates) < 0) {
    return [true, ""];
} else {
    return [false, "", "Unavailable"];
}


$(document).ready(function() {
$("#date").datepicker({
    beforeShowDay: unavailable
});
});​

When I do it with Zendx heres my form code:

$birthdate = new ZendX_JQuery_Form_Element_DatePicker('birthdate');
    $birthdate->setLabel('Return Date:')                    
                ->setJQueryParam('dateFormat', 'dd.mm.yy')
                ->setJQueryParam('changeYear', 'false')
                ->setJqueryParam('changeMonth', 'true')
                ->setJqueryParam('regional', 'en')
                ->setJqueryParam('yearRange', "2012:2012")  
                ->setJqueryParam('minDate', +1)
                ->setJqueryParam('maxDate', "+1m +10d")                 
                //->setValue(Zend_Date::now()->toString('dd.MM.yyyy'))              
                //->setJqueryParam('beforeShowDay', unavailableDates)
                ->addValidator(new Zend_Validate_Date(
                array(
                'format' => 'dd.mm.yyyy',
                )))
                ->setRequired(true);

It renders it at the top of the page:

<script type="text/javascript">

//

$(document).ready(function() { $("#birthdate").datepicker({"dateFormat":"dd.mm.yy","changeYear":"false","changeMonth":"true","regional":"en","yearRange":"2012:2012","minDate":1,"maxDate":"+1m +10d","beforeShowDay":"unavailableDates"}); }); //]]>

And I get a console error:

Uncaught TypeError: Object unavailableDates has no method 'apply'

It wont call the function unavailableDates but it just wont work. Anybody had the same issue?

Cheers

J

È stato utile?

Soluzione

I have sorted it by disabling Zend Rendering Javascript onLoad by changing the view. So now Zendx only loads in the libraries and I can run my own datepicker code in the layout :)!

this->view->jQuery() ->setRenderMode(ZendX_JQuery::RENDER_LIBRARY);

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top