#25006 closed New feature (fixed)
Allow for custom Time shortcut in DateTimeShortCuts.js
Reported by: | Ramez Issac | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | desecho@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The Time shortcut is an amazing add-on , yet it's kinda frustrating if the pre-defined shortcuts doesn't fit the field/the model or end user most used times.
Shortcut times are: Now, 00:00 , 6 a.m. and noon, ..not very handy for night fun activities i might say :-D
I managed to add this functionality through a javascript var that gets a check for existence when creating the shortcut html elements ;
if found: loop through it & get shortcut 'Name' and 'hour' difference,
Else: is the default behavior & times.
I want to hear your opinion on the most 'django' way to go about it in order to make a pull request.
Also, I apologize in advance if duplicated. (I honestly searched and couldn't find it)
Regards;
Change History (13)
comment:1 by , 9 years ago
comment:2 by , 9 years ago
I'm with you that it's not a big a deal, and hacks do exsits
However, enhancing this might not be that hard, and most probably it's gonna stay with us when the html5 comes too.
What do you think about this way...
We add a new default in the DateTimeShortCut var, it use would look like this
DateTimeShortcuts['defaultTimes'] = { 'all':[{ name : '8PM', hours:20} ,{ name : '10 PM', hours:22}], //special id, can make it _all_ to be get fancy //the default for all time fields , If not present we fall back to the django default 'id_pub_date':[{ name : '11AM', hours:11} ,{ name : '11PM', hours:23}], 'id_release_date':function(inp){ //Go Nuts ! :-) } };
?
Kind Regards;
comment:3 by , 9 years ago
I'm not too familiar with that code. If it's not much work could you implement your suggestion and send a pull request so I can better understand it?
comment:4 by , 9 years ago
Has patch: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
In the meantime, here's a pull request to add the 6 p.m. option I suggested.
comment:5 by , 9 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
The "6 p.m." PR is ready-for-commit.
comment:7 by , 9 years ago
Has patch: | unset |
---|---|
Triage Stage: | Ready for checkin → Accepted |
comment:8 by , 8 years ago
Cc: | added |
---|---|
Has patch: | set |
Version: | 1.8 → master |
Added PR
The list of hours can be overridden for each field in javascript like this:
DateTimeShortcuts.clockHours.name = [
['3 a.m.', 3]
]
where name is the name attribute of the input tag.
comment:9 by , 8 years ago
Needs tests: | set |
---|
comment:10 by , 8 years ago
Needs tests: | unset |
---|
Stackoverflow has some ideas. Admittedly, none of these look particularly robust such that we could recommend them in our docs.
I don't know that spending a lot of time trying to make it more customizable is worthwhile (can't think of an easy way), but I think an easy win for now would be to add 6pm to the list of choices so at least we're consistent with having options for every 6 hours.
I think the best long-term solution would be to switch to HTML5
input="time"
and use the widgets provided by browsers. As of now, we are missing IE and Firefox support according to w3schools.