Download & Extend

Date popups do not work when they are added by AHAH

Project:AHAH helper
Version:6.x-2.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

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.

AttachmentSize
ahah_helper_date_popup.patch520 bytes

Comments

#1

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.

#2

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?

#3

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.

#4

@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');
AttachmentSize
ahah_helper_date_popup.patch 1005 bytes

#5

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

#6

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

#7

Add to this to js:

$(function() {

$(document).ajaxComplete(function()
{

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

#8

Version:6.x-2.0» 6.x-2.x-dev
Status:active» needs review

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.

AttachmentSize
ahah_helper_797742-8.patch 1.25 KB