Why jQuery datePicker doesn't work with ajaxContext?

For programming and general questions on Zend Framework

Why jQuery datePicker doesn't work with ajaxContext?

Postby levdanski on Fri Apr 13, 2012 11:17 am

Hi,

When I render the form in view script with ajaxContext enabled, jQuery datePicker doesn't work.
It works perfectly when ajaxContext is disabled.

Here is how I added text element to the form:
Code: Select all
$textElement = new ZendX_JQuery_Form_Element_DatePicker($colName, array("label" => $textLabel." (yyyy-mm-dd)"));
$textElement->setJQueryParams(array(
                     'dateFormat'=>'yy-mm-dd',
                     'changeMonth'=> true,
                     'changeYear'=> true
                     ))
             ->setDecorators(array(
                     array('UiWidgetElement', array('tag' => '')),
                     array('Errors'),
                     array('HtmlTag', array('tag' => 'div', 'class'=>'span-11 last')),
                     array('Label', array('tag' => 'div', 'class'=>'span-5 clear'))
                         ));
             $this->addElement($textElement);


I've read everything in Internet and tried everything, but it seems that there is no clear answer.
Can somebody help?
Thanks
levdanski
 
Posts: 5
Joined: Thu Apr 12, 2012 11:34 am

Re: Why jQuery datePicker doesn't work with ajaxContext?

Postby nicoz86 on Fri Apr 13, 2012 3:24 pm

Hi,

You must use the JQuery view helper to render on load functions which initialize the date picker element.
For that, you can do <?php echo $this->jQuery(); ?> in your view script for example.

However, by doing this, you also call jQuery library and stylesheets. To avoid that, you must change the render mode to display only on load functions before rendering :
<?php $this->jQuery()->setRenderMode(ZendX_JQuery::RENDER_JQUERY_ON_LOAD); ?>

I hope this will help,

Nicolas
nicoz86
 
Posts: 2
Joined: Fri Apr 13, 2012 3:11 pm
Location: Paris (France)

Re: Why jQuery datePicker doesn't work with ajaxContext?

Postby levdanski on Fri Apr 13, 2012 4:13 pm

Nicolas,

Many thanks for advise. I tried it, still doesn't work.
At what moment the render mode should be set?

Regards,

Alex
levdanski
 
Posts: 5
Joined: Thu Apr 12, 2012 11:34 am

Re: Why jQuery datePicker doesn't work with ajaxContext?

Postby nicoz86 on Mon Apr 16, 2012 8:04 am

Alex,

You must simply set the render mode before you render the jQuery object in your ajax response.
However, you should not forget to activate the jQuery library in the overall context of the page (head tag).

Nicolas
nicoz86
 
Posts: 2
Joined: Fri Apr 13, 2012 3:11 pm
Location: Paris (France)

Re: Why jQuery datePicker doesn't work with ajaxContext?

Postby levdanski on Mon Apr 16, 2012 10:53 am

Hi Nicolas,

Thank you for your help.

I added to my page.ajax.phtml file this code:
Code: Select all
<?php $this->jQuery()->setRenderMode(ZendX_JQuery::RENDER_JQUERY_ON_LOAD); ?>
<?= $this->JQuery(); ?>


And JQuery library is in the head tag in master layout, but it has no effect.
I feel there is some stupid error, but I can't figure it out.

Kind regards,

Alex
levdanski
 
Posts: 5
Joined: Thu Apr 12, 2012 11:34 am

Re: Why jQuery datePicker doesn't work with ajaxContext?

Postby levdanski on Thu Apr 19, 2012 4:01 pm

Hi everybody,

I solved it in this manner:

1. I added to master layout the link to JQuery UI library. I think it should be stored on your server to work properly.
Code: Select all
<?= $this->headScript()->appendFile('/public/js/jquery-ui-1.7.3.custom.min.js', $type = 'text/javascript');?>
.
2. I added to view script following javascript code:
Code: Select all
$(document).ready(function(){
      $("#date").datepicker()
});


Any other solution didn't work for me.
levdanski
 
Posts: 5
Joined: Thu Apr 12, 2012 11:34 am


Return to Zend Framework

Who is online

Users browsing this forum: birc8143 and 6 guests