Default time for datetime picker widget

148 views
Skip to first unread message

libe...@gmail.com

unread,
Sep 23, 2014, 4:59:30 AM9/23/14
to web...@googlegroups.com
Hi,

I was wondering if there is an easy way to specify a default time (say 00:00)   in place of the current system time in the
datetime picker widget included in the web2py distribution

Regards

Luca

Niphlod

unread,
Sep 23, 2014, 3:14:17 PM9/23/14
to web...@googlegroups.com
Sometimes, in web2py, it's just THAT simple

import datetime
.....
Field('whatever', 'time', default=datetime.time(0,0,0))
....


;-)

libe...@gmail.com

unread,
Sep 24, 2014, 3:40:45 AM9/24/14
to web...@googlegroups.com
Thank you for the answer,

I am not sure your suggestion would work in my case. I have a datetime field that potentially can be NULL. In the form the datetime field is
represented by default by the datetime picker widget, what I am looking for is a way to let the user select a date and have the time default to
00:00:00 while leaving the user the ability to change it.

Leonel Câmara

unread,
Sep 24, 2014, 6:19:07 AM9/24/14
to web...@googlegroups.com
Put it as a placeholder?

Luca Liberti

unread,
Sep 24, 2014, 8:01:59 AM9/24/14
to web...@googlegroups.com
Thank you

I tried modifying the model as
Field('model_end_time', type='datetime',represent=lambda x, row: 'Active' if x is None else x.strftime("%Y-%m-%d"),default=datetime.datetime.now().replace(hour=0,minute=0,second=0, microsecond=0))

I find that the datetime picker control still defaults to the current system time regardless the fact that the field is empty or not

I there anything I am making wrong



On Wed, Sep 24, 2014 at 12:19 PM, Leonel Câmara <leonel...@gmail.com> wrote:
Put it as a placeholder?

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/AHiFwg2tZ4I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Niphlod

unread,
Sep 24, 2014, 3:22:16 PM9/24/14
to web...@googlegroups.com
let's break it down a bit.....
It's one thing to have a field "prefilled" with a default value and it's a totally different one to have a field empty by default but when you click on it it "presets" the time to 00:00.

The former needs a Field(...., default=something), the latter, given that the date(time) input is "managed" by a javascript component, needs a "javascript" tuning.

Unfortunately, it seems that the version we're using can't accomodate for a "default time" for a datetime.

Luca Liberti

unread,
Sep 30, 2014, 10:00:20 AM9/30/14
to web...@googlegroups.com
What I was looking for was exactly some hint on how to do some "javascript" tuning from within web2py. I am aware this might be a "borderline" question not
completely belonging to the forum.

Thank you

--

Massimo Di Pierro

unread,
Oct 3, 2014, 7:26:51 AM10/3/14
to web...@googlegroups.com
There is a new undocumented feature in web2py: ASSIGNJ

def index():
    return dict(a={'whatever': ['you', 'want']})

# in view
<script>{{=ASSIGNJS(whatever=whatever}}</script>

now whatever is a JS variable.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages