db.define_table('cal_form',
Field('date_in','date'))
def datepicker():
form=SQLFORM(db.cal_form)
if form.process().accepted:
response.flash = 'form accepted'
elif form.errors:
response.flash = 'form has errors'
else:
response.flash = 'please fill out the form'
return dict(form=form)
{{extend 'layout.html'}}
{{block head}}
<link rel="stylesheet" type="text/css" href="/calendar/static/css/jquery.datetimepicker.css"/ >
<script src="/calendar/static/js/jquery.datetimepicker.full.min.js"></script>
{{end}}
<h2>Input form</h2>
{{=form}}
<script>
$(document).ready(function(){
jQuery('#cal_form_date_in').datetimepicker({
timepicker:false,
format:'Y-m-d',
yearStart: '1940'
});
});
</script>
Field('mydate', 'date', widget=SQLFORM.widgets.string.widget)
Field('mydate', 'date',
widget=lambda f, v: SQLFORM.widgets.date.widget(f, v, data=dict(w2p_date='disabled'))
That simply adds a "data-w2p_date" attribute to the input element. This only works because the presence of the "data-w2p_date" attributes tricks the click handler into thinking the calendar widget has already been set up on the input field, so it doesn't attempt to set it up again (note, the value "disabled" is arbitrary -- any value at all will work there).
Anthony