Include the necessary files by adding this to your model or controller:
response.files.append("http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js")
response.files.append("http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-darkness/jquery-ui.css")
Copy the widget code to your model:
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:'yy-mm-dd'});});" % inp['_id'],_type="text/javascript")
wrapper.components.extend([inp,jqscr])
return wrapper
Apply the widget to a field:
db.define_table("test",Field("posted","date",widget=date_widget))
Try it out in your controller:
def index():
form = SQLFORM(db.test)
if form.accepts(request.vars,session):
response.flash = "Got it"
all = db().select(db.test.ALL)
return dict(form=form,all=all)
Demo application (right click/Save As): Download
Comments (3)
0
apardue 14 years ago
0
mrfreeze 14 years ago
0
apardue 14 years ago