Active
Project:
Date
Version:
7.x-2.6
Component:
Date Popup
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Anonymous (not verified)
Created:
21 Sep 2012 at 08:30 UTC
Updated:
20 Mar 2025 at 12:29 UTC
I'm creating a form which I'm showing in a block.
This form contains a date popup field.
I noticed the datepopup javascript is not working when block caching is enabled.
(It only works right after a cache clear.)
Somehow drupal_add_js isn't triggered anymore.
I fixed it by adding
'cache' => DRUPAL_NO_CACHE
to my block.
I couldn't find the real problem..
Code below.
/**
* Implements hook_block_info().
*/
function hotels_block_info() {
$blocks = array();
$blocks['hotels-search'] = array(
'info' => t('Hotels search block'),
//it works if we add the line below
//'cache' => DRUPAL_NO_CACHE,
);
return $blocks;
}
/**
* Implements hook_block_view().
*
* Show a block with a the search form for hotels.
*/
function hotels_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'hotels-search':
$block['subject'] = t('Search & book hotel');
$block['content'] = drupal_get_form('hotels_search_form');
break;
}
return $block;
}
function hotels_search_form($form, &$form_state) {
$form['start'] = array(
'#type' => 'date_popup',
'#label' => '',
'#date_format' => 'd-m-Y',
'#date_label_position' => 'hidden',
'#title' => t("From"),
'#attributes' => array('placeholder' => t("Start date")),
'#required' => TRUE,
'#size' => 20,
'#date_year_range' => '-0:+2',
);
[...]
}
Comments
Comment #1
ccoreilly commentedI can confirm this issue, any idea on why this is happening?