Hi.

From everything I've read, I should be able to get a date picker to appear when adding node content, like I could under Drupal 5. I've installed and enabled JQuery UI (6.x-1.2), JQuery update (6.x-1.1) and JQuery plugins (6.x-1.7) under Drupal 6.12, but I just get the plain old text field. I've spent a lot of time Googling, without success, so figured I'd try a support request. I assume it's something I'm doing wrong or expecting that's not implemented.

Regards,

Nigel

CommentFileSizeAuthor
#1 date.module.patch.txt680 bytesbrice-dupe
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

brice-dupe’s picture

FileSize
680 bytes

Nigel,

I was able to get this to work by adding to the Date module's "hook_form_alter". There is NO NEED for jQuery UI and jQuery plugins. Make sure you include the Calendar Popup module that is in the Dates package. Here's what I did specifically:

Edit date/date/date.module

add

if (isset($form['author']['date']))
{
	$form['author']['date']['#type'] = 'date_popup';
	unset($form['author']['date']['#maxlength']);
}

to the function date_form_alter() function [@ line 443].

Attached is a patch. You can of course create your own module and hook into alter_form.

Hope this helps!

~ Brice

Nigel Cunningham’s picture

Thanks for the reply and sorry I've been so slow to notice it. I'll give this a try.

Nigel

Nigel Cunningham’s picture

Status: Active » Closed (fixed)

That works beautifully!

Thank you very much!

csc4’s picture

Status: Closed (fixed) » Active

Sorry to reopen this - but could I just clarify...

Is this the official answer?

That the module doesn't support this feature any more and that we should roll a custom patch if we still need this functionality? or is it a bug that the feature has gone away? or is there a setting somewhere which needs changing?

RobLoach’s picture

Title: Can't get Date Popup to appear for 'Authored on' field when adding content. » Use Date Popup on 'Authored on' field
Version: 6.x-2.2 » 6.x-2.x-dev
Category: support » feature
Status: Active » Needs review

Stick this in date_popup.module.......

/**
 * Implementation of hook_form_alter().
 */
function date_popup_form_alter(&$form, $form_state, $form_id) {
  if (strstr($form_id, '_node_form') !== FALSE) {
    $form['author']['date']['#type'] = 'date_popup';
  }
}
brice-dupe’s picture

I have noticed that this is skewing the hour published. Whenever I use date_popup as the #type of the node_form .... it increments time published by one hour! You can repeat this by saving a node. Edit it and save (without changing anything). The hour will have incremented.

Any ideas?

RobLoach’s picture

Might be your timezone conversion? Might also be unrelated to this issue.....

brice-dupe’s picture

Rob,

Are you able to repeat this?

On my server; timezone is set to American/Kentucky/Monticello. User selectable timezones are disabled.

I have also tried to set Timezone to UTC and it still skews.

The date_popup widget creates two input fields. One to select a date via the calendar popup, and another for the time. The time of day field is quirky. There seems to be some client side code that limits you to typing eoith the hour or second.

seworthi’s picture

Following up on #5 solution, if you also use the "override_node_options" module, you will need to use the following to adjust for that modules 'date' filed changes.

function date_popup_form_alter(&$form, $form_state, $form_id) {
  if (strstr($form_id, '_node_form') !== FALSE) {
		if (isset($form['author']['date'])) {
			$form['author']['date']['#type'] = 'date_popup';
			unset($form['author']['date']['#maxlength']);
		} else {
			//fix node_override
			$form['author']['override_authored_on']['#type'] = 'date_popup';
			unset($form['author']['override_authored_on']['#maxlength']);
		}
  }
}
mohanrajthangarasu’s picture

that works beautifully. thanks Seworthi

Jax’s picture

sub

Jax’s picture

Status: Needs review » Needs work

After applying the change in #5 I'm getting the error warning: mb_strlen() expects parameter 1 to be string, array given in /home/ojacquet/public_html/recticel/includes/unicode.inc on line 407. because the "Authored on" info is no longer sent as a string but as an array:

array
  'date' => string '2009-11-23' (length=10)
  'time' => string '10:57' (length=5)
drupalina’s picture

I have tried codes in both #1 and #5, but it keeps adding 9 hours (same problem as reported in #6). The server is located in USA, but the site timezone is in GMT+4 (I don't know if this could be one of the problems, but the codes in #1 or #5 seem to skip that which Drupal achieves pretty neatly - i.e. respect the time and timezones).
This is very problematic because very often if an article is added in the evening, then with +9 hours the date of the article will change to the next date. This is a really needed feature because people will be manually adding more than 70,000 nodes from back issues and I just wanted to added some sort of date-popup so as to ease their lives. Can someone help or provide an alternative solution, please? I'm sure this is a very needed feature!
Many-many thanks!

sjz’s picture

I'm experiencing the same problem where the "picker" is not respecting the time zone differential. Too bad to because it would be SO much more user-friendly than the current implementation.

Mac Clemmens’s picture

Is there a way to adjust the input from this form element +/- the user's timezone?

/**
* Implementation of hook_form_alter().
*/
function date_popup_form_alter(&$form, $form_state, $form_id) {
  if (strstr($form_id, '_node_form') !== FALSE) {
    $form['author']['date']['#type'] = 'date_popup';
  }
}
drupalina’s picture

Regarding #6 and #13 I've managed to resolve it by setting up the site timezone in .htaccess file. At the vey begining of it I entered:
SetEnv TZ :Europe/Prague and now the date popup solution from #5 no longer messes up the time and dates.

But in my watchdog logs I still get a PHP ERROR
mb_strlen() expects parameter 1 to be string, array given in /home/example/www/www/includes/unicode.inc on line 404.

Any solutions for this string/array php error???

ianchan’s picture

subscribe

CKIDOW’s picture

subscribe

skilip’s picture

The 'mb_strlen' error is caused by the '#maxlength' property. Unset it.

Nigel Cunningham’s picture

The patch in #9 works for me without timezone issues or errors in syslog.

grandchamp_g’s picture

I've tired both #1 and #5 and neither seem to work, it changes the field by making it shorter and allowing only the short date format I have setup as input. But there is no pop-up. Can anyone help me? What am I doing wrong?

barraponto’s picture

patches published as a module in http://drupal.org/project/date_popup_authored, but i suppose it is still prone to the same issues reported here...

Mark Trapp’s picture

@barraponto When I rolled the date_popup_authored module, I did look through the issues here to see if there was things that could be addressed. However, none of these issues are actually caused by the patch/module: #6, #8, and #14 are all related to timezone issues outside the scope of the patch/module, whereas #16 is related to missing one of the lines necessary for the patch. From my testing, if your timezones are properly configured, the patch (and the module) should work just fine.

lee20’s picture

subscribe

Mark Trapp’s picture

Status: Needs work » Needs review

I identified the timezone problems you guys have experienced and have fixed this in 6.x-1.0-beta2 of Date Popup Authored (see: #847854: Timezone handling is poor to non-existent.). If you don't want to use the module, here's the modified code:

/**
 * Implementation of hook_form_alter().
 */
function date_popup_authored_form_alter(&$form, $form_state, $form_id) {
  if (strstr($form_id, '_node_form') !== FALSE) {
    $form['author']['date']['#type'] = 'date_popup';
    unset($form['author']['date']['#maxlength']);
    unset($form['author']['date']['#description']);
    
    // We need to modify date popup's data during submit
    // @see <url omitted>
    $form['#submit'][] = 'date_popup_authored_node_form_submit';
  }
}

/**
 * Submits the node data with the proper post date.
 *
 * @see <url omitted>
 */
function date_popup_authored_node_form_submit($form, &$form_state) {

  // Determine user's timezone and convert the date to the authored field format.
  $timezone = date_default_timezone_name();
  $time     = date_make_date($form_state['values']['date'], $timezone, DATE_DATETIME);

  $form_state['values']['date'] = date_format_date($time, 'custom', 'Y-m-d H:i:s O');
} 
h2odigital’s picture

Title: Use Date Popup on 'Authored on' field » Date Popup
Category: feature » support
Mark Trapp’s picture

Title: Date Popup » Use Date Popup on 'Authored on' field
Category: support » feature
klonos’s picture

Version: 6.x-2.x-dev » 7.x-2.x-dev

...coming from #1562798: Its hard for users to provide valid input in the authoring date field (which is an issue filed against D8 core). There is no action here for more than two years now. Let's see if we can get this moving by assigning it to the latest dev of D7.

barraponto’s picture

date is in core. is the picker in core? should we move this issue to core's queue?

klonos’s picture

barraponto’s picture

Status: Needs review » Closed (duplicate)

As explained in #30.