I have noticed that date popups do not work when they are added by AHAH on a form which is using the ahah_helper module.
adding a call to drupal_get_js() in the 'data' part of the array that is rendered back to the form via JSON seems to fix the problem. I am not sure if this breaks anything elsewhere, but doing some testing everything still seemed to work fine, and the date popups now function when they are added via AHAH.
i've attached a patch to cover this.

Comments

tayzlor’s picture

after some further testing, the above patch breaks modal dialog functionality if an ahah form is rendered in a ctools modal. What will happen is that the modal will load if you click a link on a page first time round, then if you click on an ahah behaviour, close the modal, then try to re-open it by clicking the link, the javascript will not fire and the page will redirect to the nojs page.

tayzlor’s picture

related post - http://drupal.org/node/244025#comment-2546764 , which explains my patch, but the patch seems to break the modal stuff as explained above. any ideas?

cristhian’s picture

Patch seem to be correct, getting new js is missing.

About the ctools modal, have you tried commenting ahah_helper.js? I had a similar behaviour, but only when a form input realoaded itself with ahah_helper. I noticed for some reason in ahah_helper.js it breaked before Drupal.attachBehaviors, so ahah stopped working. Then I commented all in that file and got no problem, at this point I'm not sure what's the difference between leaving it or not.

tayzlor’s picture

StatusFileSize
new1005 bytes

@Cristhian

commenting out that file makes no difference - the call to drupal_get_js() causes problems with other scripts on the page.
After a bit of further investigation it seems the main problem is because the settings for the AHAH added date_popup field are not passed out through the ahah_helper_render() function.

The new javascript files which are called by calling date_popup_load() and through date_popup_js_settings_id() are also not added.
Could the new JS files be loaded by integrating with the ajax load module, by implementing the _alter() hook before the data is rendered out in JSON?

I am attaching a patch to cover adding the date popup settings back to the form through the ahah render function.
To ensure the date popup will work the js will need to be on the page when the page is loaded, which you can achieve by doing -

    date_popup_load();
    drupal_add_js(drupal_get_path('module', 'date_popup') .'/date_popup.js');
Alun’s picture

subscribe. Many thanks for working on this bug - its an issue for my module.

FranciscoLuz’s picture

@tayzlor #4
Thank you, this is the best solution I have found on this issue.

shekar.kyatam’s picture

Add to this to js:

$(function() {

$(document).ajaxComplete(function()
{

$("#edit-cheque-date").datepicker({
changeMonth: true,
changeYear: true,
yearRange: '1970:2020',
dateFormat: 'dd-mm-yy'
});
});
}

adamdicarlo’s picture

Version: 6.x-2.0 » 6.x-2.x-dev
Status: Active » Needs review
StatusFileSize
new1.25 KB

Here's the patch from #4 rerolled from head and in git format. Also with whitespace errors fixed and capitalization/punctuation in first comment fixed.