Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
If date fields are read from a table and rendered using #type => 'date' , a value of '0000-00-00' in the field will cause the rendered date to be 1900-1-1. The following patch adds a key value of 0 in $options array of day,month and year i.e $options[0] = '--'; causing the date to be displayed as -- -- --.
Comment | File | Size | Author |
---|---|---|---|
form.inc.patch_2.txt | 553 bytes | debdungeon |
Comments
Comment #1
drummThis needs review.
Comment #2
Dries CreditAttribution: Dries commentedI don't think this is a problem in forms.inc. It looks like a problem with the calling code ... you should provide such dates to the forms API.
Comment #3
debdungeon CreditAttribution: debdungeon commentedThis happened to me when using datetime fields in mysql. The value returned was '0000-00-00' which when rendered as $form['somedate'] = array('#type' => 'date', '#value' => array('day' => 0, 'month' => 0, 'year' => 0)) will result in 1900-01-01 as there is no key value of 0 in any of the selects.
Comment #4
drummInstead of adding another option, can we have it go to today's date instead?
I think a new option needs consideration of things like validation. A required date field needs to have all of the values set.
(And the current convention for Drupal code is to use unix timestamps rather than SQL dates so format_date() may be used on output.)
Comment #5
Dries CreditAttribution: Dries commentedI still think this should be marked "won't fix". If you want the current date, specificy the current timestamp.
Comment #6
debdungeon CreditAttribution: debdungeon commentedBut thats exactly my problem. There are a number of date fields like date_of_accident, date_of_bill etc. Some have valid values while others have value of '0000-00-00'. If the 0 key value is not present all date fields for which no specific date value is selected, will be updated to 1900-1-1 or current_date which would be incorrect.
The current cvs version has date_validate function which catches 0000-00-00 dates in case of required date fields.
I personally prefer unix timestamps but I happen to be working on a database provided by the client. I am just developing an interface around the db.
Comment #7
ricabrantes CreditAttribution: ricabrantes commentedThis bug is active??
Comment #8
sean.mtm CreditAttribution: sean.mtm commentedI'm looking at essentially the same issue but from a different angle - there's no way to have a null-value with the date selector. To see a case where this would be relevant, I'm making an input for an 'event'. An event may be a single day or it may span multiple days (thus having a start date & an end date). Start date is a required value but the end date is not - a null in the end date would indicate a single-day event.
With the current date input, there is no clear & unambiguous way of not entering a date.
Comment #9
Jaza CreditAttribution: Jaza commentedI agree that this issue is still relevant. @sen.mtm is right: there is no way to not enter a date with the current FAPI date processor.
BTW,
expand_date()
is nowform_process_date()
.Moving.
Comment #10
jhedstromDates can be optional in the form API.