Hello

I have the following problem:
 - i have a sqlform with a date field (which I customized with a jquery 
widget, that, among other things, changes the date format into dd/mm/yy) 
which works fine (displays the correct format after date selection) but if 
the form validation fails than the "saved" value of the date field gets 
reformatted back to '%Y-%m-%d' default format.

this is the field value in the table:

Field('data', 'date', widget=date_widget, 
requires=[IS_NOT_EMPTY(error_message="Completarea campului este 
obligatorie"),
                                                                       
IS_DATE('%d/%m/%Y', error_message = 'Data trebuie sa aiba formatul 
ZZ/LL/AAAA') ],
        label="Data Nasterii", comment="")

db.table.data.represent = lambda value,row : value.strftime('%d/%m/%Y')

and the date widget:

def date_widget(f, v):
    wrapper = DIV()
    inp = SQLFORM.widgets.string.widget(f, v, _class="jqdate")
    jqscr = SCRIPT(
        "jQuery(document).ready(function(){\
                        jQuery('#%s').datepicker({\
                            dateFormat:'dd/mm/yy',\
                            showOtherMonths:true,\
                            selectOtherMonths:true,\
                            changeYear:true,\
                            yearRange: '-80:+0',\
                            changeMonth:true\
                            });\
                        });" % inp['_id'],
        _type="text/javascript")
    wrapper.components.extend([inp, jqscr])
    return wrapper

also i have included the translation in my language file:
'%Y-%m-%d' : '%d/%m/%Y',
'%Y-%m-%d %H:%M:%S': '%d/%m/%Y %H:%M:%S',
'%d.%m.%Y': '%d.%m.%Y',
'%d.%m.%Y %H:%M:%S': '%d.%m.%Y %H:%M:%S',
'%d/%m/%Y': '%d/%m/%Y',
'%d/%m/%Y %H:%M:%S': '%d/%m/%Y %H:%M:%S',

and changed the default format in web2py_ajax.html:
    var w2p_ajax_date_format = "{{=T('%d/%m/%Y')}}";
    var w2p_ajax_datetime_format = "{{=T('%d/%m/%Y %H:%M:%S')}}";

i'm running out of ideas so i thought maybe you could help.

thanks
'web2py newbie' :)


-- 



Reply via email to