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")
Add the widget in db.py
def slider_widget(f,v):
wrapper = DIV(_id="slider_wrapper",_style="width: 200px;text-align:center;")
inp = SQLFORM.widgets.string.widget(f,v)
sld = DIV(_id='slider_' + inp['_id'])
sldval = SPAN(inp['_value'],_id=sld['_id']+'_val')
scr1 = "jQuery('#%s').hide();" % inp['_id']
scr2 = "jQuery('#%s').val(ui.value);jQuery('#%s').text(ui.value);" % (inp['_id'], sldval['_id'])
jqscr = SCRIPT(scr1,"jQuery('#%s').slider({value: '%s',stop: function(event, ui) {%s}});" % \
(sld['_id'],inp['_value'],scr2),_type="text/javascript")
wrapper.components.extend([sld,sldval,inp,jqscr])
return wrapper
Create a test table and set the widget to our new slider widget
db.define_table("test",Field("num","integer",widget=slider_widget))
Create a form 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 (0)