If you set a date field as required, it will be populated with today's date/time even if the default value is set to "blank". Even though the field is required, it should be blank and show an error on submit when left empty.

1) type of field: date
2) type of widget: text
3) timezone option: any
4) no multiples
5) yes required

I'll see if I can find the problem and submit a patch later...

Comments

threexk’s picture

I agree with wazdog's assessment of how it should work. Could not figure out why it was populating the current date until I saw this post.

karens’s picture

Status: Active » Fixed

The problem is that when you mark a date required it doesn't include a blank value option for any of the date parts, which seems like a logical way for it to behave. I changed the code to provide a blank value if the date is required but empty so now I just need to watch this for a while to be sure it doesn't introduce any other problems now that non-allowed values are in the options list.

threexk’s picture

Status: Fixed » Active

Karen, thanks for the fix but it doesn't seem to blank text fields, just select lists. (Many of our date fields are preferably text fields to speed data entry.)

I agree with you it is logical to default a valid value for a required field. However, the problem we in particular are having is that on our medical website we need to capture correct dates, for instance birth dates, but it is all too easy for a user to submit the form without changing the default date. So we end up with many birthdays being the current date. (Good validation should catch this, but for other date fields the current date is a valid entry too!) A blank required date will always force the user to enter a date.

Using the 4-18-08 dev snapshot.

karens’s picture

I understand the use case for this, I just forgot to go back and get this working with text fields as well as select lists :)

Working on this now...

karens’s picture

Status: Active » Fixed

OK, textfield dates should now be working. Let me know if there are problems.

threexk’s picture

The textfields come up blank now, but won't submit when filled in. I get the following form errors from two date textfields:
A valid date cannot be created from
A valid date cannot be created from

The input format is specified as 04/22/2008 - 00:09:28, and I have only month, day, and year checked.

May not be related, but I also see extra vertical space between the form label and textfield. Poked into with Firebug, and found the field curiously contains two form-items:

<div class="form-item">
   <label for="edit-field-dob-0-value">
   Date of Birth:
   <span class="form-required" title="This field is required.">*</span>
   </label>
      <div class="date-date">
      <div class="form-item">
         <input id="edit-field-dob-0-value-date" class="form-text required error date-date" type="text" value="" size="60" name="field_dob[0][value][date]" maxlength="128"/>
      </div>
   </div>
</div>
karens’s picture

Status: Fixed » Active

Marking back to active until I get it fixed.

karens’s picture

Status: Active » Fixed

OK, the empty but required textfield should now be working right with the latest commits.

The extra form div is because we are nesting elements and the inner one is automatically created by core. Not sure I can do anything to get rid of it, but at any rate is doesn't affect this problem and isn't critical.

threexk’s picture

Fix works, thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

threexk’s picture

Status: Closed (fixed) » Active

The To Date is not blanked; it always has a default value. I am using the following settings:
Widget: Select List
Default value: Blank
To Date: Optional

Sorry, I didn't test this case before.

karens’s picture

Status: Active » Fixed

Open up the advanced default options to set a default value for the to date.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

graemec’s picture

Karen,

Do you know where I can download this patch that you and threexk are referring to?

Much appreciated.

threexk’s picture

graemec: 5.x-2.x-dev has this code in it. If a patch to 5.x-2.0-rc is what you need though, maybe Karen could provide that. I don't immediately know how to build a patch off the associated commits.