Changes between Version 38 and Version 39 of S3/FilterForms

04/02/13 09:27:55 (11 years ago)
Dominic König



  • S3/FilterForms

    v38 v39  
    215215=== Using Filter Forms in REST Method Handlers ===
    217   * ''tbw''
     217Filter 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.
     219'''A filter form can be generated using the S3FilterForm class''':
     222from s3filter import S3FilterForm
     223filter_form = S3FilterForm(widgets, **attr)
     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||
     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||
     241'''The filter form can then be rendered using its .html() method''':
     244html_output = filter_form.html(resource, get_vars, target=None, alias=None)
     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||
    219254=== Using Filter Forms in Custom Controllers ===