Closed (won't fix)
Project:
Drupal core
Version:
x.y.z
Component:
base system
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
28 Oct 2004 at 03:55 UTC
Updated:
10 Feb 2006 at 21:37 UTC
Jump to comment: Most recent file
Comments
Comment #1
moshe weitzman commenteddupe of http://drupal.org/node/9371. please close that one or move your patch there. also, it would be good to use this function in profile.module. that illustrates the usefulness of the new function.
Comment #2
dries commentedPlease update the profile module to use the new form_date() function. (Should the archive module use it too?)
Comment #3
gordon commentedThis is a great idea, as I have often wanted a date entry field. But the problem that I see is that you can still enter an invalid date, and dividing it accross fields looks a little ugly.
What would be good is to add an ability to data type fields on submit and return the converted date. i.e. have a single field and allow the entering of a validate date. eg. "2 Jan 1970" and it would make sure this is a valid date and convert it seconds (86400) so that all the other validation functions will see the internal format which will be a valid date, or else it will pass back an error.
This would mean that when we are specifing fields for a particular type of data, eg. date, time, numeric, integer, etc we would be able to do a pre-validate and make sure these correct before the real validation is done. This means that the real validation don't need to worry about making sure that data is in the correct format.
One idea that with these data typed fields is to add a hidden field that has a list of all the typed fields to be checked, before the _validate() hook is called.
I also think this may future proof this area a bit for when web forms becomes a lot more accepted and we will be able to use <input type="date" /> instead of cobbling something together.
Comment #4
Bèr Kessels commentedI am not happy with the three separate text boxes.
Better would be, if they are dropdowns (often used; recognising UIs is useability improvement). Or even with some javascript (allthough that would start flamewars IMO. An example is in a new trip search @ http://gworks.ca/drupal-cvs/?q=trip_search/advanced look in the bottom)
problem: Those only fascilitate gregorian calendars
So maybe the option would be to make the parsing very smart. Then we can have just a textfield, where people can add whatever they want and a localised template, together with some smart preg-replaces will do the trick.
After all: calendars and date formats are all about localisation! And useability is all about KISS on the user side of things. I beleive three form elements for one entry is not KISS.
For gregorian european calendars the locale templates would be
Best is to follow the PHP date tokens as close as possible in these templates.
if in above example a user adds 22/11/1978 the system can find the date and will know the users means 22nd of november 1978.
Comment #5
Steven commentedI don't like the textboxes either. In profile.module, I used dropdowns. I also used the month shortname rather than a number. This makes it easy to read dates that have already been filled in (what date is 01/02/03 vs 1 Feb 2003).
I also wonder why you're using directly rather than form_*() functions. You can use .container-inline to inline controls on one line.
Comment #6
Chris Johnson commentedSo much to respond to here. I'll try to address all of the remarks.
#1.
I do not believe this is a duplicate of http://drupal.org/node/9371, unless we want to rule out any of the back-end data validation ideas that were mentioned in that task. My intention was to build one or more new HTML form functions, and not to make sweeping changes across how the core handles data input and validation. Right now it appears most validation is custom built into each module. So I think HTML form generation and form data validation are two different tasks, although very closely related. I can imagine a new architecture for form handling which would marry or join the two pieces, HTML and validation, but that would pretty much mean rewriting almost all of common.inc plus every module. I'm not qualified to do that in Drupal! :-) (I do however, do just exactly that in my proprietary application where this idea came from -- see #3 below.)
If you all still disagree, I'll be happy to close http://drupal.org/node/9371 and point a response here.
#2.
I'll be more than happy to update the profile module and anywhere else that would be appropriate. Removing code is always a happy task.
#3.
Unless we use dropdowns (see further discussion below) or Javascript, it will always be possible to enter an invalid date until Preview/Save causes the backend to validate it. However, using a single text field, instead of 3, means that dates can be entered in so many formats, one will never be able to validate them. With 3 fields, it's easy to validate each. As for appearance being ugly: (1) I can tweak the HTML a little bit, and with optional CSS styling, they can be made to look much better. This is, in fact, how I use this code in my applications. I use Drupal's common.inc, modified to run outside of Drupal and with my added date form function to drive a bunch of proprietary forms. They are extensively styled with CSS. One example can be seen here: http://www.visi.com/~chris/date.html (2) What is ugly to one person is not to another, so I am opposed to arbitrarily not implementing a feature just because some people think it is ugly.
I'm not sure I get all the rest of Gordon's points. Maybe he will clarify?
Let me just reiterate that there are too many valid date formats to allow the user to just type a date into a single text box. Just for starters: 2004-09-30, 2004-9-30, 2004.09.30, 2004.9.30, 9/30/04, 9/30/2004, 9-30-2004, and the always entertaining: 11/10/2004, 11-10-2004, 11.10.2004, 2004-10-11, etc.
#4.
And I hate dropdowns. Ok, I really don't but it is a valid but not winnable argument to prefer one or the other. For people who touch type and like to keep their hands on the keyboard, dropdowns are a pain in the neck. They also take more screen real estate, and are slower. I've got a lot of experience and background in designing user interfaces and human factors. It is unfortunately not a simple case of one being better than the other. I actually would prefer having both available if it can be done in some clean, efficient way.
The idea of parsing and figuring out what date is really meant from a single text box certainly sounds attractive on the surface, but there is just no way to know what a user means when he types 10/11/2004. Is that November 10 or October 11? Using a localized template and preg_replace means all users have to enter their dates in the same format, does it not?
I'm all in favor of KISS, believe me. After writing UI software for 27 years, KISS is my guiding principle in everything I do. Making users conform to one idea of how to enter dates is hostile to the users who like to do it in another format.
#5.
I agree dropdowns with month shortname are easier to read. I often write dates that way by hand, on paper and in computer text becaues of its clarity. If there is no way the powers that be will accept text boxes only, or text boxes and dropdowns, user or admin or programmer's choice, then I'll recode my patch to use dropdowns. But as I said before -- I personally hate them when filling in a form with multiple items because I'm typing on the keyboard and want to keep my hands there. I can make dropdowns work form the keyboard but they do not behave consistently. One has to stop and watch what is happening to make sure the value they wanted is the one selected, especially with numerics.
As for the (I'm guessing, because of the missing words, probably HTML that got filtered out by Drupal) using HTML input elements directly instead of the form_ calls: I found that in order to get the closest fit and best styling of the input fields, that it was necessary to do this. The extra wrapping divs around the form_ calls introduce extra white space between the elements. Beats me as to why -- I suspect it is a rendering bug in Firebird and MSIE on Windows (only places I have tested it).
** Lastly, if I can get a form_date patch accepted, I'm interested in and willing to create a form_time function and/or a combined date and time function if you all think they are worth doing.
Comment #7
Steven commentedI think for Drupal, with a large international audience, it is important to keep the date selector as unambiguous as possible.
The 3 textboxes allow you to mix up day and month, the dropdowns do not. In Ffox, I can still select values in a dropdown by just typing them out, so I don't really see a problem. The dropdowns are also better because it is immediately obvious what a certain filled in value means.
Also, I don't really see your point with not using container-inline & form_ functions: it would be tons cleaner and consistent. If the spacing is not 100% right, use some CSS to fix it up.
Lastly, I'm not sure I like the naming 'drupal_'.$name.'_'.$type. Firstly we never use a 'drupal' prefix like that anywhere. Secondly, it would be better to make $name an array with day/month/year elements.
Comment #8
Chris Johnson commentedIt's true that 3 textboxes allow one to type the day value into the month and vice versa. In normal usage, there would be some kind of prompt or text indicating the correct order. In my application, I preset the value to "mm" and "dd" for the month and day respectively and the user then types over them. One could also put that information in the $description or as background images in the CSS, etc. However, I agree thiis is the best reason for using dropdowns.
As for Firefox allowing allowing you to select dropdown values by typing: no, Firefox fails in exactly the way I was referring to. Yes, you can type to get the value you want eventually, but it does not do so in a consistent way. Example: go to a day dropdown (1-31). Preset it to 1, change focus away and then change focus back (e.g. using tab) so that you come into the field as a normal user might, then imagine that you wanted to type "31" but accidentally typed "13". Now type 13 and then 31 without any other kepresses in an effort to fix what you typed. It will continue to display 13 even though you typed 31. Maybe that is a minor enough problem that most Drupal users are willing to live with it. In a data entry application this kind of nonsensical behavior is not acceptable.
As for the spacing issue -- as I said, there appears to be a bug. CSS will NOT fix it.
I don't like the 'drupal_'.$name.'_'.$type thing much either, but was trying to avoid namespace conflicts. Passing an array is a fine solution for the form variable names, but it then raises the question of what the name of the entire date item (all 3 dropdowns) is for CSS and HTML "label" purposes is.
It appears I'm in the minority on the text boxes vs. dropdowns issue, so I will revise the patch to use dropdowns and also look at adding an array of names.
I will also attempt to make a demo available to show various options and problems associated with them.
Comment #9
Steven commented"As for the spacing issue -- as I said, there appears to be a bug. CSS will NOT fix it."
It is very rare for a spacing issue to occur both in IE and Firefox. I'm sure there's just some theme CSS setting margins.
Wrap the form date control in a div class="form-date", then set .form-date select { margin: 0px; } or something.
Comment #10
Chris Johnson commentedQuestion: when using dropdowns, what range should the year selection cover? For the profile module, the range is 1900 to 2050.
What if a module developer were creating a module for soemthing that contained dates further in the past, e.g. biographical information?
Should the year range be passed as an argument to form_date()?
Although in the Gregorian calendar, all years have 12 months with a fixed number of days, would we want to likewise allow the caller to pass in the allowed ranges for month and day?
Comment #11
Chris Johnson commentedQuestion: when using dropdowns, what range should the year selection cover? For the profile module, the range is 1900 to 2050.
What if a module developer were creating a module for soemthing that contained dates further in the past, e.g. biographical information?
Should the year range be passed as an argument to form_date()?
Although in the Gregorian calendar, all years have 12 months with a fixed number of days, would we want to likewise allow the caller to pass in the allowed ranges for month and day?
Comment #12
nevets commentedWhen using a single text box for date input, the date can be parsed withstrtotime() which understands a varity of formats for dates (see http://www.gnu.org/software/tar/manual/html_chapter/tar_7.html)
One concience of this is you can type nov 4 and it assumes nov 4, 2004,
Comment #13
nevets commentedWhen using a single text box for date input, the date can be parsed withstrtotime() which understands a varity of formats for dates (see http://www.gnu.org/software/tar/manual/html_chapter/tar_7.html)
One concience of this is you can type nov 4 and it assumes nov 4, 2004,
Comment #14
Chris Johnson commentedHere is another proposed patch. This one includes:
1. Dropdown lists instead of text boxes.
2. Calls to form_select() instead of raw HTML.
3. Optionally allows caller to specify the year range, defaults to -125/+50 years from today.
4. Container class "container-inline".
Open issues:
1. The $required parameter is only useful for styling/marking the element as required. Validating that it was filled in is of no use because dropdown lists always have a valid date, although not necessarily the right one.
2. There is no way to refer to the entire element of all 3 dropdowns together in CSS because there is no global name for them. Thus, there is no way to call _form_get_error() or _form_get_class() on the created date element.
Suggestions and advice on the above 2 issues would be appreciated.
Comment #15
gordon commentedfor all the restrictiveness of the the entry field to the entry, you can still enter invalid dates such as the 31 Feb. Then the modules that use this will then need alway validate to make sure this is a valid date.
What about extensions on this. What about a date time field which could be used by modules like the event module. Having typed fields like this I would expect that I would receive a valid date, and also in a common format. Allowing for localisation differences such as MM/DD/YYYY or DD/MM/YYYY as simple ones.
Comment #16
puregin commentedHello all,
If we are willing to permit a little JavaScript/DOM
code, it's relatively easy to implement client-side constraints
on dropdown lists to permit only valid dates to be entered
(with leap-years properly accounted for).
I have a little snippet of such code available for people to try out
and use if they find it useful. Please have a look at
http://www.puregin.org/downloads/date_widget
This solution only deals with the Gregorian calendar.
Best regards, Djun
Comment #17
gordon commentedUsing js is an options, but I know that I would prefer to see no js in core. You should be able to add additional code with some popup calendars but this should be done via the theme, and not forced upon everyone.
Comment #18
Bèr Kessels commented-1 for javascript. We have not used it anywhere else in core, i do not like the idea of introducting it for this function
I like the idea of using strtotime (http://be2.php.net/manual/en/function.strtotime.php). In combination with localisation, this will follow the "be generous in what you accept, but strict in what you provide" filosofy.
Comment #19
gordon commenteddefinate -1 to Javascript. The core needs to be kept as assessible as possible, so that you can do everything from a browser such as lynx. This was the main reason that I got rid of all the javascript out of the configuration of htmlarea for 4.5
Comment #20
Steven commented+1 on degradable JS though ;).
Comment #21
chx commentedResetting to active. Awaiting new patch according to what we have agreed at the usability meaning.
Order shall be controlled be locale.
Comment #22
Chris Johnson commentedStill need guidance on how to solve this open issue:
2. There is no way to refer to the entire element of all 3 dropdowns together in CSS because there is no global name for them. Thus, there is no way to call _form_get_error() or _form_get_class() on the created date element.
I'll take chx's remarks and rework the patch soon.
Thanks.
Comment #23
jjeff commentedI realize that I wasn't at the usability meeting, and please excuse me if I'm chiming in on something that's already been thoroughly thought out, but one of the big advantages that I see of form_date standardization is the ability to implement travel-site style DHTML calendar date/time choosers. Say what you will about accessibility and standards compliance, but it's really nice, quick, and easy to point and click on a calendar. And for novice users (read 'everyone but us developers') GUI rules.
I hope that there will be hooks and standardized field names so that the form fields/menus can be easily manipulated by JavaScript, and that modules can really get "in there" pre and post.
Better yet would be to completely open it up so that modules could completely develop their own date/time input formatting. This would address all of the date formatting issues on this page and admins could (for instance) be able to have a setting to choose in what format they would like date fields displayed. Then dates would be output based on admin settings wherever form_date() was called. You want one field for everything? Great. Separate menus for y/m/d/h/m/s? Do it. Combo DHTML and textfields? No problem! Tie it to locality? Just put it in the module.
Also, keep in mind that from a Unix timestamp point of view, date and time are part of the same stamp. So I would suggest that a "proper" form_date would allow for any amount of granularity.
Again, just my 2 cents (adjusted for the weak dollar).
-Jeff
Comment #24
Bèr Kessels commentedThe date function is themable, like any other of these form functions. As long as you return a unix timestamp, you can do pretty much everything with this function in your theme.
We should not add hooks and such to this rather simple function, but leave it to the theme to just override it.
Comment #25
jjeff commentedSounds good to me. I just wanted to make sure that these issues were considered.
Thanks Bèr.
-Jeff
Comment #26
Chris Johnson commentedThis feature is obviated by the 4.7 Forms API. A new issue for adding this kind of widget is open there, I believe. Don't have the number handy.