Whenever I build a form and add more date-enabled fields to it using the AHAH api, reloading the section that contains all of the date popup fields, none of the date popup fields are date popup enabled (they are simply textfields).

Steps to create:
1. Create a form with a date popup field.
2. Setup AHAH to add another date popup field, with the method set to 'replace'
3. Click the AHAH button.

(This is very similar to #244025: JQuery Calendar quits working when you add a new field)

CommentFileSizeAuthor
#16 filename.patch1.81 KBbwynants

Comments

marz71’s picture

I have the same problem. When I add some ahah components and refresh wrapper using ahah, the date_popup calendar does not popup anymore.

Regards,
Marek

cvandyke’s picture

I have the exact same problem.

timtrinidad’s picture

+1

vip_sa’s picture

Title: Date Popup stops working after adding more fields with AHAH » Date Popup stop working

The date pop up on my site just do not work. I am using IE8 and Firefox 3.52. I have installed the jquery UI module but still I cannot get the date pop up to appear on any browser

niklp’s picture

I have installed the JQuery UI module and added the download as instructed - the instructions aren't great, and there's no warning as to whether that's happened or not, that I can make out anyway. That's more the problem of the JQuery UI module however.

Works in Flock 2.0, IE 7, but not Firefox 3.5

talino’s picture

Same here. I had to deactivate JQuery UI, which works in Safari & Opera but not in Firefox.

bwynants’s picture

Same problem here, I add an extra 'date_popup' type fields via a #ahah wrapper and the popup-calender no longer pops up on the 'date_popup' type fields. They did work before I clicked the #ahah button however

bwynants’s picture

double post

emptyvoid’s picture

Status: Active » Closed (duplicate)

Similar discussion here: http://drupal.org/node/436490 (Add support for jQuery update to 1.3.x and jQuery UI 1.7.x)

I posted a css update

m.crane’s picture

Status: Closed (duplicate) » Active

This is definitely not a duplicate - that problem is the date popup looking bad when you update jQuery. This problem is that, when using AHAH, the date popup functionality of fields is lost (they worked properly before additional fields are added) when more fields are added (which should have date popup functionality).

bwynants’s picture

very true!

wanghl165’s picture

same here

wanghl165’s picture

date popup module sets the date field ids and settings in the Drupal.settings.datePopup, then Drupal.behaviors.date_popup looks for ids only existing in it and bind event for them. but after adding more date fields by ahah, the new ids of the new date field are not in the Drupal.settings.datePopup, that is why date popup doesn't work with ahah.
So I create a js file to find all the date fields by its' name like 'input[name*="[date_begin][date]"]' and 'input[name*="[date_begin][time]"]' but not its' id and make the first item in the Drupal.settings.datePopup as the arguments of the bind event, then, rebind event like date_popup.js.

Finally, it works with ahah.

bwynants’s picture

do you have a patch available?

wanghl165’s picture

This is not patch, it is just a way to make date popup work with ahah
AHAH wrapper:

<div id="edit-selects-0-date-begin-wrapper" class="form-item">
  <label for="edit-selects-0-date-begin">Pickup Date: </label>
  <div id="edit-selects-0-date-begin-datepicker-popup-0-wrapper" class="form-item">
    <input id="edit-selects-0-date-begin-datepicker-popup-0" class="form-text" type="text" value="" size="20" name="selects[0][date_begin][date]" maxlength="30"/>
    <div class="description"> Format: 12/08/2009</div>
  </div>
  <div id="edit-selects-0-date-begin-timeEntry-popup-1-wrapper" class="form-item">
    <input id="edit-selects-0-date-begin-timeEntry-popup-1" class="form-text" type="text" value="" size="10" name="selects[0][date_begin][time]" maxlength="10"/>
    <div class="description">Format: 04:21</div>
  </div>
</div>

js code:

/**
 * Attaches the calendar behavior to all required fields
 */
Drupal.behaviors.reservation = function (context) {
  if(Drupal.settings.datePopup) {
    var argDate = Drupal.settings.datePopup['edit-selects-0-date-begin-datepicker-popup-0'];
    var argTime = Drupal.settings.datePopup['edit-selects-0-date-begin-timeEntry-popup-1'];
    
    $('input[name*="[date_begin][date]"]').bind('focus', argDate, function(e) {
      if (!$(this).hasClass('date-popup-init')) {
        var datePopup = e.data;
        // Explicitely filter the methods we accept.
        switch (datePopup.func) {
          case 'datepicker':
            $(this)
              .datepicker(datePopup.settings)
              .addClass('date-popup-init')
              .focus();
            break;
        }
      }
    });
    $('input[name*="[date_begin][time]"]').bind('focus', argTime, function(e) {
      if (!$(this).hasClass('date-popup-init')) {
        var datePopup = e.data;
        // Explicitely filter the methods we accept.
        switch (datePopup.func) {
          case 'timeEntry':
            $(this)
              .timeEntry(datePopup.settings)
              .addClass('date-popup-init')
              .focus();
            break;
        }
      }
    });
  }
}
bwynants’s picture

StatusFileSize
new1.81 KB

based on your solution I made this patch.
Not sure why your date fields have a -begin in the ID's however

Anyway apart from the lookup $('input[name*="[date][date]"]') I have no hard coded strings in this patch....

mafioso’s picture

Version: 6.x-2.2 » 6.x-2.4

already tried the patch but didn't work for me.

bwynants’s picture

what is the id of your input fields in the html?
eg: id="edit-selects-0-date-dateEntry-popup-1"

mafioso’s picture

bwynants,

The #15 workaround works for me, like wanghl165 on #13 wrote:

...So I create a js file to find all the date fields by its' name like 'input[name*="[date_begin][date]"]' and 'input[name*="[date_begin][time]"]' but not its' id and make the first item in the Drupal.settings.datePopup as the arguments of the bind event, then, rebind event like date_popup.js.

so, i did replace [date_begin][date] with the value of the name attribute only, not the ID.

bwynants’s picture

as I said my input fields are named [date][date] yours seem to be called [date_begin]

in the first line of the patch I look for [date][date], change that to [date_begin][date]

+ $('input[name*="[date][date]"]').each(

a proper solution must be found by the module maintainer I guess

sukr_s’s picture

a simpler solution is to return the necessary js functions in your ahah handler

function my_ahah_hander(){

//ahah processing
$output = ....

$output .= theme('status_messages') . drupal_get_js();

drupal_json(array('status' => TRUE, 'data' => $output));
}

This works fine with the pop ups, but I faced the problem with submit. $form_state['values']['my_date_field'] did not have the value that was entered. So I used the $_POST['my_date_field'] value and this works fine...

function my_form_submit_handler($form,&form_state){
 ....
$my_date_field=$_POST['my_date_field'];
}
karens’s picture

Title: Date Popup stop working » Problems using Date Popup with custom AHAH code
Category: bug » support
Status: Active » Fixed

This is not a bug report, it is a support request about how to add custom AHAH handlers to an already very complex field.

I can't help you much here, getting this stuff working in the first place was very challenging. If you want to do things like add your own AHAH handlers to the mix you're pretty much on your own.

It sounds like there are ideas in the issue that you can use.

If someone wants to add some documentation to the handbook about how to get this stuff working it would be great, but I'm really not able to support every kind of custom adaptation of the code anyone might come up with. My focus in this issue queue is making sure that the out of the box code works.

bwynants’s picture

you did fix it in #560054: Create and remove multiple repeat exceptions (without needing to save node for every exception) ! see date_repeat_form.inc

  // Force a rebuild of the Drupal.settings javascript object.
  //   - Borrowed from content.node_form.inc, content_add_more_js function
  $javascript = drupal_add_js(NULL, NULL);
  $output_js = isset($javascript['setting']) ? '<script type="text/javascript">jQuery.extend(Drupal.settings, '. drupal_to_js(call_user_func_array('array_merge_recursive', $javascript['setting'])) .');</script>' : '';

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

marthinal’s picture

Theres another easy way .i change the id with jQuery and then i execute Drupal.attachBehaviors($('#edit-date-start-datepicker-popup-0')); to the id ....here you have working the date popup also.

FranciscoLuz’s picture

Hi folks,

Make use of ahah_helper module (Dev version at 25 Feb 2011 or later) and apply this patch here http://drupal.org/node/797742#comment-3036010.
This, among other things, will fix the data popup issue.