Default value for To date: Blank should stay blank

meba - July 18, 2009 - 07:45
Project:Date
Version:6.x-2.x-dev
Component:Date CCK Field
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Description

When creating Date field with To date as optional, I set "Default value for To date" to Blank. All correct, when I create the node, the value is blank. But immediatelly when you save it, From: value is filled in.

I think that Blank should stay blank - no value at all.

#1

masande - July 22, 2009 - 19:36
Version:6.x-2.2» 6.x-2.x-dev

i can confirm this bug with the dev version, too. the problem is exactly as the original poster describes – by leaving the optional 'to' date blank, it is populated by drupal with the 'from' date. i'd really like it if the blank field remained blank.

#2

masande - July 27, 2009 - 14:49
Status:active» needs review

i think i have figured this out. in order for date_elements.inc to perform validation on fields with both a from and to value, the $to_date is set to match $from_date even if the $to_date is left blank. what i have done to remove the $to_date (if that field is marked as optional) is to NULL $item[$to_field] is $from_date == $to_date. i don't think this will be a problem since if both dates match that means there the 'to date' field has not been optionally set.

i've attached a patch. please be kind since this is the first patch i've ever contributed.

AttachmentSize
date_elements.patch 968 bytes

#3

nsciacca - July 31, 2009 - 22:31

The only I dislike about this patch is that it assumes that if the dates are equal that they were set by the system and the to value should be cleared. You should flag line 480 where it sets the "$to_date = $from_date;" when in the else of "if (!empty($field['todate'])) {" and then blank out the "to_date" later on if the flag was set. This is what I did, seems to work, not going to make a patch just yet....

(line numbers approximate.... sorry)

line 481
$from_date = date_input_value($field, $element[$from_field]);
if (!empty($field['todate'])) {

// Nsciacca: adding flag here.. I'm going to clear out the to value if it was forced
$tofieldelement = $element[$to_field];
$field_name = $tofieldelement['#field']['field_name'];
$postvalues = $element['#post'][$field_name];
if ($postvalues[$tofieldelement['#delta']]['value2']['date'] == '' ) {
$forced_to_date = TRUE;
}

$to_date = date_input_value($field, $element[$to_field]);
}
else {
$to_date = $from_date;
}

....

line 544
if (empty($errors)) {
// Nsciacca: if we flagged the date, clear it out
if ($forced_to_date) $item[$to_field] = '';
form_set_value($element, $item, $form_state);
}

#4

arlinsandbulte - August 1, 2009 - 14:37

I marked #427772: To Date showing incorrectly in Preview/Edit as a duplicate of this issue.

I agree that an optional "to date" should remain blank.
I also agree with nsciacca that assuming that if the dates are equal that they were set by the system and the to value should be cleared is the wrong approach. There are instances when I WANT to fill in the from and to dates with the same value.

Nsciacca's logic above looks right to correct the issue (I have not tested it), but I think this may also be the wrong approach.
Instead of doing all this extra work & overhead to let the "to date" get set and then later blank it out, why not just change it so the optional "to date" never gets filled in?

#5

LinL - August 2, 2009 - 10:58

@arlinsandbulte Thanks for picking up my issue #427772: To Date showing incorrectly in Preview/Edit and for the heads up about the latest version.

A quick update to my earlier issue report.

I stated that an optional blank to date is populated with the from date in the preview/edit page, but it is saved correctly. I should have said that it is shown correctly when the node is saved, but the database fields field_name_value and field_name_value2 are saved with the same date (the from date). As I only use the dates in a generated node title, built from date tokens, I've got round the bug, but I'd agree that it is a bug and optional blank to dates should remain blank.

#6

LinL - August 2, 2009 - 11:10

#7

drj8022 - August 18, 2009 - 14:46

I've encountered this issue as well (To date not staying blank). Running Drupal 6.6. Tested Date 2.2, Date 2.3, and the -dev versions of the module all experienced this issue. Adding the patch to 2.3 fixed the date not staying blank problem. But there is another bug as well.

-- Still Grabbing From Date --
I created a custom content type to describe some projects I'm working on. I want to show site visitors a listing of all my projects, sortable by "Node:title" or "Date:to". I created a new view, add node title field, add active dates field, format active dates to "Display to date only", set view style to 'table", made the columns sortable, and selected the date field as the default sort. When I browse to the view, dates are wrong. If "Date:to" is blank, dates are displayed as "Date:from" and sorted thusly. Other dates display normally.

We think it's an issue of the Date module being unable to differentiate between "Date:to" and "Date:from" when you're in the view style settings. (eg.. change style to "table", click the gear, the options list only shows "date" under field and column.) This should not be the case, as my field is field_active_dates, and has been formatted to "Display to date only".

Any suggestions for a patch or workaround?

Extreme thanks in advance!

#8

drj8022 - August 25, 2009 - 15:29

Using this workaround for now:

1. Entering a "to date" in the future.
2. Created several theme overrides to display future dates as 'ongoing' sitewide.

Thanks!

#9

marcushenningsen - October 26, 2009 - 16:50

By coincidence I just found out that this (on my machine) is related to the devel_themer module. Can I anyone confirm this? If you're experiencing this issue, try to disable the devel_themer module and see if it disappears.

Marcus

#10

Jeff - November 6, 2009 - 13:07

I'm encountering the problem as well and I don't use the devel_themer module marcus, so it might be related, but it wouldn't be only that relation. I'll test the solution suggested by nsciacca (http://drupal.org/node/523218#comment-1875950)

edit: I must admit though, it doesn't show the to-date in my views etc if I didn't set it myself. I'm perfectly happy with that, since I don't expect my data to change a lot (seminars and events like that usually don't change dates or names).

#11

ssemigr - November 13, 2009 - 09:26

subscribing

#12

BrightBold - November 21, 2009 - 02:52

Subscribing. Same problem.

 
 

Drupal is a registered trademark of Dries Buytaert.