217 | | * ''tbw'' |
| 217 | Filter forms can be rendered by any method handler. Since filter forms will never be submitted, the method handler does not need to handle any subsequent POSTs related to the filter form, but just insert the filter form HTML to the page. |
| 218 | |
| 219 | '''A filter form can be generated using the S3FilterForm class''': |
| 220 | |
| 221 | {{{#!python |
| 222 | from s3filter import S3FilterForm |
| 223 | filter_form = S3FilterForm(widgets, **attr) |
| 224 | }}} |
| 225 | |
| 226 | '''Parameters''': |
| 227 | ||'''Parameter'''||'''Type'''||'''Explanation'''|| |
| 228 | ||widgets||list of S3FilterWidget instances||the widgets for the filter form ''(required)''|| |
| 229 | ||attr|| ||Options and HTML attributes for the filter form|| |
| 230 | |
| 231 | '''Options and HTML attributes''': |
| 232 | ||'''Parameter'''||'''Type'''||'''Explanation'''||'''Default'''|| |
| 233 | ||formstyle||function||a function to render a widget row, must accept {{{(row_id, label, widget, comment)}}} as parameter list||S3FilterForm._formstyle()|| |
| 234 | ||submit||boolean or the button label as string/lazyT or a tuple (label, HTML class)||whether to render a submit button in the filter form and how, with {{{False}}} or {{{None}}} no submit button will be rendered||False (if True, then the label defaults to T("Search"))|| |
| 235 | ||ajax||boolean||whether to Ajax-update the target object (True, also requires the target to be specified in the html() call) or re-load the page (False)||False|| |
| 236 | ||url||string||where to load the filtered data from||URL of the request|| |
| 237 | ||ajaxurl||string||where to load option updates for filter widgets from||URL of the request + /filter.json method|| |
| 238 | ||_class||string||the CSS class for the filter form ''(HTML attribute)''||"filter-form"|| |
| 239 | ||_id||string||the HTML element ID for the filter form ''(HTML attribute)''||None|| |
| 240 | |
| 241 | '''The filter form can then be rendered using its .html() method''': |
| 242 | |
| 243 | {{{#!python |
| 244 | html_output = filter_form.html(resource, get_vars, target=None, alias=None) |
| 245 | }}} |
| 246 | |
| 247 | '''Parameters''': |
| 248 | ||'''Parameter'''||'''Type'''||'''Explanation'''|| |
| 249 | ||resource||S3Resource||The resource to render the filter form for. Important: do not just use the {{{r.resource}}} instance here (because it's coming with pre-filtered options), instead create a new instance using {{{s3db.resource(r.resource.tablename)}}} ''(required)''|| - || |
| 250 | ||get_vars||dict||the GET vars (=URL query vars) to populate the filter widgets from ''(required)''|| - || |
| 251 | ||target||string||the HTML element ID of the target object (e.g. a datalist or datatable) ''(required if the form is set to ajax=True)''||None|| |
| 252 | ||alias||string||the table alias to use in URL queries ''(required if the filtered resource is not the master resource of the request URL, e.g. a component)''||None|| |