Hi!
I would really like to have the date field as blank when required. The problem on my site is that people are too sloppy when signing up and just except the default, hence many people are born in 2007.
So, I would really want to push the user to do an active choice, have the default as blank and the field as required.

In Date 2.0:

The Date module now has lots of new ways to define default values -- you can set a the default to 'blank'

Is there a way to hack the 1.8 to get this feature? Right now I decided to not even use the 'Date' field and have a normal integer field, just to get the blank (many drawbacks).

All suggestions are wellcome! Thanks a lot!
Seth

Comments

karens’s picture

Status: Active » Fixed

There's always a way to hack things if you want to spend time figuring out how to get it to work and doing all the debugging, but this will be in 5.2 which is almost ready, so I won't be adding it to 5.1.8 or spending any time to figure out how it could be done.

beautifulmind’s picture

You could use php function 'strtotime()' to store data as integer and while retrieving from db use format_date() function of drupal.
Hope this could be helpful.

seth97’s picture

Ok, I'll wait for the 5.2.
Thanks!
Seth

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

threexk’s picture

I was less patient than poster and wrote a module to do it. It blanks all date field default values without discrimination.

date_blankfields.module:

// $Id$

function date_blankfields_form_alter($form_id, &$form) {
   foreach (array_keys($form) as $key) {
      if (strstr($key, "field")) {
         $field = &$form[$key];
         foreach (array_keys($field) as $key) {
            if (strstr($key, "#theme")) {
               if ($field[$key]['#theme'] = 'date_form_fieldgroup') {
                  unset($field['0']['value']['#default_value']);
               }
            }
         }
      }
   } 
}

date_blankfields.info:

; $Id$
name = Date Blank Fields
description = "Make CCK date fields blank by default."

I'm a PHP novice, so if there is a more condensed way to code it, I'd be interested to know. (Some curly braces could've been omitted for one-line conditional bodies.)

wongle’s picture

I just noticed that this will also blank date fields that have data in them when going to edit a node...

threexk’s picture

Thanks for pointing that out. A little hack to check whether we're on an add-node page fixes the problem for me.

date_blankfields.module:

// $Id$

function date_blankfields_form_alter($form_id, &$form) {
   if (arg(1) == 'add') {
      foreach (array_keys($form) as $key) {
         if (strstr($key, "field")) {
            $field = &$form[$key];
            foreach (array_keys($field) as $key) {
               if (strstr($key, "#theme")) {
                  if ($field[$key]['#theme'] = 'date_form_fieldgroup') {
                     unset($field['0']['value']['#default_value']);
                  }
               }
            }
         }
      } 
   }
}

I'm still using this little module because 5.x-2.0-rc won't blank a required date field. See #234073: Setting a date field as required shows today's date even if default value is "blank".