if you need a cutsom widget with a custom format, and you already rewrote 
the widget, why don't you rewrite also the validator ?!

On Wednesday, June 24, 2015 at 10:00:46 AM UTC+2, Annet wrote:
>
> I wrote a widget to format time:
>
> 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='form-control time_plain', 
> _name=field.name, value=str(value), requires=field.requires)
>
> and on the fileds of type time I have the following attributes:
>
> istime = dict(type='time', requires=IS_TIME(error_message='Formaat komt 
> niet overeen met HH:MM'), widget=timeplain)
>
>
> This works fine unless the form contains an error on the field of type 
> time, for example I have the following validation function:
>
> def __onvalidation_openinghours(form):
>     if form.vars.startTime > form.vars.endTime:
>         form.errors.endTime = 'De eind tijd is vroeger dan de start tijd'
>
> In this case the endTime is displayed in the format HH:MM:SS
> The issue can be fixed by adding:
>
> form.vars.endTime = form.vars.endTime.strftime('%H:%M')
>
> after form.errors.endTime, however, I wonder whether there is a way to 
> adjust the timeplain function to solve the issue.
>
>
> Kind regards,
>
> Annet
>
>
>
>

-- 
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 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/d/optout.

Reply via email to