It would be nice to have the "to" date prepopulated based on what the user picks in the "from" date. So if the default value for the form is now and the user picks October 3, 2010 as the "from" date, the "to" date switches from now to October 3, 2010.

Comments

Melissamcewen’s picture

Title: Prepopulate "to" date based on "from" date? » Dynamically fill "to" date based on "from" date?

FYI here is some Jquert you can use for this




<script>
$(document).ready(function() {
 
 	$("#ID-of-from-field").change(setHour) 	
})

function setHour() {
 	$("#ID-of-to-field").val($("#ID-of-from-field").val())
}

</script>

If anyone else is interested in having this in Date or another module I could work on it...

Renee S’s picture

Dirty hack, probably not best practice, but it works and might help :)


// $Id: date_popup.js,v 1.1.2.4 2010/11/20 12:03:36 karens Exp $

/**
 * Attaches the calendar behavior to all required fields
 */
Drupal.behaviors.date_popup = function (context) {
  for (var id in Drupal.settings.datePopup) {
    $('#'+ id).bind('focus', Drupal.settings.datePopup[id], 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')
            $(this).click(function(){
              $(this).focus();
            });
			// The magic happens here. This isn't great: it only works on date fields with times on 'em...
			// But a starting point, anyway.
            $("input.date-popup-init:first").change( function() {
				$(":input:eq(" + ($(":input").index(this) + 2 ) + ")").val( $(this).val() );
			});
            break;

          case 'timeEntry':
            $(this)
              .timeEntry(datePopup.settings)
              .addClass('date-popup-init')
            $(this).click(function(){
              $(this).focus();
            });
            break;
        }
      }
    });
  }
};
apoc1’s picture

Component: Date CCK Field » Code

Any idea, how to make this happen in D7?

damienmckenna’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

Unfortunately the Drupal 6 version of the Date module is no longer supported. That said, we appreciate that you took time to work on this issue. Should this request still be relevant for Drupal 7 please feel free to reopen it. Thank you.