I think this is a bug - my usecase was:

Content type Doodle - why not use it for polls too? So I added a pollfield and thought that I can choose which one to use in "Edit".

But even when I don't enter a date in the date picker formatter field, one field will always show up in the resulting node (with an error, because no time given).

The field is not required, so when I don't select a date, no field should show up - at least that's how e.g. imagefield and a normal date field behave. Any idea...?

(Still a great module. I will quite certainly use it for my project!)

Comments

zeropaper’s picture

Ok, this might indeed be a bug needing further investigation.

could you post the content type definition? Would be handy for debug.

Have a nice evening (I guess we're on the same time zone ;) )

itsnotme’s picture

Guten Morgen ;) Thanks for reacting so fast. I tried to have a look into CCK fields but frankly, the code went way over my head.

Here the content types definition:

$content['type']  = array (
  'name' => 'Doodle',
  'type' => 'doodle',
  'description' => '',
  'title_label' => 'Title',
  'body_label' => 'Body',
  'min_word_count' => '0',
  'help' => '',
  'node_options' => 
  array (
    'status' => true,
    'promote' => false,
    'sticky' => false,
    'revision' => false,
  ),
  'upload' => '0',
  'show_preview_changes' => 0,
  'ffp_upload' => 
  array (
    'file_path' => '',
    'file_path_cleanup' => 
    array (
      'file_path_pathauto' => 0,
      'file_path_tolower' => 0,
      'file_path_transliterate' => 0,
    ),
    'file_name' => '[filefield-onlyname-original].[filefield-extension-original]',
    'file_name_cleanup' => 
    array (
      'file_name_pathauto' => 0,
      'file_name_tolower' => 0,
      'file_name_transliterate' => 0,
    ),
    'retroactive_update' => '',
  ),
  'private' => 1,
  'old_type' => 'doodle',
  'orig_type' => '',
  'module' => 'node',
  'custom' => '1',
  'modified' => '1',
  'locked' => '0',
  'og_content_type_usage' => 'omitted',
  'content_profile_use' => 0,
  'comment' => '0',
  'comment_default_mode' => '4',
  'comment_default_order' => '1',
  'comment_default_per_page' => '50',
  'comment_controls' => '3',
  'comment_anonymous' => 0,
  'comment_subject_field' => '1',
  'comment_preview' => '1',
  'comment_form_location' => '0',
  'comment_upload' => '0',
  'comment_upload_images' => 'none',
  'ffp_comment_upload' => 
  array (
    'file_path' => '',
    'file_path_cleanup' => 
    array (
      'file_path_pathauto' => 0,
      'file_path_tolower' => 0,
      'file_path_transliterate' => 0,
    ),
    'file_name' => '[filefield-onlyname-original].[filefield-extension-original]',
    'file_name_cleanup' => 
    array (
      'file_name_pathauto' => 0,
      'file_name_tolower' => 0,
      'file_name_transliterate' => 0,
    ),
    'retroactive_update' => '',
  ),
  'notifications_node_ui' => 
  array (
    'block' => true,
    0 => 1,
    'form' => false,
    'comment' => false,
    'links' => false,
    'teaserlinks' => false,
    'subform' => false,
  ),
  'notifications_content_type' => 
  array (
    'taxonomy' => true,
    'grouptype' => true,
    'thread' => true,
    'nodetype' => true,
    'author' => true,
    'typeauthor' => true,
  ),
  'print_display' => 0,
  'print_display_comment' => 0,
  'print_display_urllist' => 0,
  'ant' => '0',
  'ant_pattern' => '',
  'ant_php' => 0,
);
$content['fields']  = array (
  0 => 
  array (
    'label' => 'doodledate',
    'field_name' => 'field_doodledate',
    'type' => 'datetime',
    'widget_type' => 'date_popup',
    'change' => 'Change basic information',
    'weight' => '31',
    'default_value' => 'blank',
    'default_value2' => 'same',
    'default_value_code' => '',
    'default_value_code2' => '',
    'input_format' => 'm/d/Y - H:i',
    'input_format_custom' => '',
    'year_range' => '-3:+3',
    'increment' => '1',
    'advanced' => 
    array (
      'label_position' => 'above',
      'text_parts' => 
      array (
        'year' => 0,
        'month' => 0,
        'day' => 0,
        'hour' => 0,
        'minute' => 0,
        'second' => 0,
      ),
    ),
    'label_position' => 'above',
    'text_parts' => 
    array (
    ),
    'description' => '',
    'group' => false,
    'required' => 0,
    'multiple' => '1',
    'repeat' => 0,
    'todate' => '',
    'granularity' => 
    array (
      'year' => 'year',
      'month' => 'month',
      'day' => 'day',
      'hour' => 'hour',
      'minute' => 'minute',
    ),
    'default_format' => 'medium',
    'tz_handling' => 'none',
    'timezone_db' => '',
    'op' => 'Save field settings',
    'module' => 'date',
    'widget_module' => 'date',
    'columns' => 
    array (
      'value' => 
      array (
        'type' => 'datetime',
        'not null' => false,
        'sortable' => true,
        'views' => true,
      ),
    ),
    'display_settings' => 
    array (
      'weight' => '31',
      'parent' => '',
      'label' => 
      array (
        'format' => 'hidden',
      ),
      'teaser' => 
      array (
        'format' => 'hidden',
        'exclude' => 0,
      ),
      'full' => 
      array (
        'format' => 'date_picker_formatter',
        'exclude' => 0,
      ),
      5 => 
      array (
        'format' => 'default',
        'exclude' => 0,
      ),
      4 => 
      array (
        'format' => 'default',
        'exclude' => 0,
      ),
      2 => 
      array (
        'format' => 'default',
        'exclude' => 0,
      ),
      3 => 
      array (
        'format' => 'default',
        'exclude' => 0,
      ),
      'token' => 
      array (
        'format' => 'default',
        'exclude' => 0,
      ),
    ),
  ),
);
$content['extra']  = array (
  'title' => '-5',
  'body_field' => '0',
  'revision_information' => '20',
  'comment_settings' => '30',
  'menu' => '-2',
  'book' => '10',
  'path' => '30',
  'print' => '30',
);
zeropaper’s picture

ok, got it.

I'll commit the change within few days.
If you're interested by the solution, I added a small check in the theme_date_picker_formatter_formatter_date_picker_formatter($element) function, which now looks like:

function theme_date_picker_formatter_formatter_date_picker_formatter($element) {
  if (count(element_children($element)) <= 1 || date_content_is_empty($element[0], content_fields($element['#field_name'], $element['#node']->type))) {
    // the field is empty and should not be rendered
    return '';
  }
  return drupal_get_form('date_picker_formatter_form_'. $element['#node']->nid .'_'. $element['#field_name'], $element['#node'], $element['#field_name']);
}
itsnotme’s picture

Just tested it. It stops the empty field from appearing...

...but unfortunately it also stops the valid fields from appearing.

zeropaper’s picture

Status: Active » Needs review

Damn it. I forgot to use my brain...

function theme_date_picker_formatter_formatter_date_picker_formatter($element) {
  $field = content_fields($element['#field_name'], $element['#node']->type);
  $first_item = (array)$element[0]['#item'];
  if (count(element_children($element)) <= 1 || date_content_is_empty($first_item, $field)) {
    // the field is empty and should not be rendered
    // @todo try to prevent empty field processing earlier
    return '';
  }
  return drupal_get_form('date_picker_formatter_form_'. $element['#node']->nid .'_'. $element['#field_name'], $element['#node'], $element['#field_name']);
}

Should be ok.

itsnotme’s picture

Yes, this looks very fine! Thank you so much!

I'll do some more testing here (alone and in combination with Pollfield) before I implement it in my Intranet, so if I come across anything else, I'll drop a note.

(And in case you'll attend the Drupalcamp in Essen - you're invited to a drink :)

zeropaper’s picture

I wish I could come to Essen ;( but I can't afford myself a ticket and I'm overloaded with work (RESET.to goes India very soon)...
Whatever, feedback will always be welcome.

Have a nice day

itsnotme’s picture

Sorry to hear about Not!Essen :(

I think I found another little bug - when only one valid field is added, it's still not shown. (Okay, it makes no sense to add just one Doodle date, but I guess it's unintentional to filter that).

itsnotme’s picture

The bug that a single doodle field is not displayed can be fixed by correcting line 442 (I hope that's the right line for everyone):

if (count(element_children($element)) <= 1 || date_content_is_empty($first_item, $field)) {

to

if (count(element_children($element)) < 1 || date_content_is_empty($first_item, $field)) {

A simple <= to < makes all the difference here :) Thanks again for the cool module.

socialnicheguru’s picture

subscribing. this little fix works! Thanks!

inak’s picture

found another solution which will fix it directly at the beginning (added another condition to the if clause, and initialized the form):

around Line 178:

//  zdpm($date_picker_formatter);
$form = array();
  if (isset($field_name) && isset($node->{$field_name}) && $node->{$field_name}[0]['value']!='') {
    $date_picker_formatter = date_picker_formatter_get_votes($node, $field);
thepanz’s picture

Is this issue still valid for 2.x branch?