On Thursday, February 7, 2013 2:53:50 AM UTC-5, Gerd wrote:
>
>
>
> Am Donnerstag, 7. Februar 2013 00:20:02 UTC+1 schrieb DenesL:
>>
>>
>>
>> On Wednesday, February 6, 2013 8:24:01 AM UTC-5, Gerd wrote:
>>>
>>> Hi Annet and DenesL!
>>>
>>> @DenesL: Yes, did restart it, nothings changed
>>>
>>
>> True. Note that the input will show HH:MM:SS until you click on it, then 
>> it becomes HH:MM.
>>
>
> Thats what i described in the starting thread 
>

Oh yeah, I was not able to open the images in the original post so I got 
distracted in the middle of it but I should have re-read the whole thing.
 

>  
>>
>>>
>>> @Annet: Thanks you very much, you got it
>>>
>>> regards
>>> Gerd
>>>
>>> Am Mittwoch, 6. Februar 2013 13:31:24 UTC+1 schrieb Annet:
>>>>
>>>> Hi Gerd,
>>>>
>>>> So if i understand this right there is no possibility to change the 
>>>>> representation in an update form?
>>>>>
>>>>
>>>>
>>>> Yes, besides, I am not sure whether IS_TIME() has a format property 
>>>> like IS_DATE() and IS_DATETIME() have.
>>>> In 2009 it hadn't, and Chris helped me solve the problem as follows:
>>>>
>>>> In db.py:
>>>>
>>>> istime = dict(type='time',requires=IS_TIME(error_message=T('no match 
>>>> HH:MM')),widget=timeplain,comment=T('Format HH:MM'))
>>>>
>>>> Field('startTime',**istime),
>>>> Field('endTime',**istime),
>>>>
>>>> In a module:
>>>>
>>>> def timeplain(field,value): 
>>>>     if value == None: 
>>>>         value = ''
>>>>     elif 'strftime' in dir(value):
>>>>         value = value.strftime('%H:%M') 
>>>>     id = '%s_%s' % (field._tablename, field.name) 
>>>>     return INPUT(_type='text',_id=id,_class='time_plain',_name=
>>>> field.name,value=str(value),requires=field.requires)
>>>>
>>>
>> The only caveat here is that you will not be using jQuery.timeEntry, 
>> unless you change the class to just 'time'.
>> You can also do:
>>
>> widget=lambda field,value: SQLFORM.widgets.time.widget(field, 
>> value.strftime('%H:%M') if value else '')
>>
>> but you still need to add {showSeconds:false} to .timeEntry in web2py.js
>>
>>
> I see, thank you very much DenesL 
>

To avoid modifying web2py.js we could do:

script=SCRIPT('jQuery(document).ready(function(){jQuery("input.mytime").timeEntry({showSeconds:false});});')
widget=lambda field,value: TAG[''](SQLFORM.widgets.time.widget(field, 
value.strftime('%H:%M') if value else '', _class='mytime'),script)

and add that widget to the required fields in the model:
Field(..., widget=widget)

this way we can pass any parameters to jQuery.timeEntry as we need  ;)
 

>  
>>
>>>
>>>> and in case you need it, in a view:
>>>>
>>>>   {{=table.startTime.strftime("%H:%M")}}
>>>>
>>>>
>>>> Kind regards,
>>>>
>>>> Annet
>>>>
>>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to