You can submit multiple inputs (via id) with the ajax() function, so if you
give your checkbox inputs id's (e.g., id='title' and id='body'), you should
be able to do:
ajax('callback', ['keyword', 'title', 'body'], 'target')
and in the controller, access request.vars.keyword, request.vars.title, and
request.vars.body (I think title and body will be None if they are not
checked).
Anthony
On Tuesday, December 27, 2011 2:29:56 PM UTC-5, smirghor wrote:
>
> In the example in chapter 3 of the book, mywiki application we have:
>
> def search():
> "an ajax wiki search page"
> return dict(form=FORM(INPUT(_id='keyword',_name='keyword',
> _onkeyup="ajax('callback', ['keyword'], 'target');")),
> target_div=DIV(_id='target'))
>
> def callback():
> "an ajax callback that returns a <ul> of links to wiki pages"
> query = db.page.title.contains(request.vars.keyword)
> pages = db(query).select(orderby=db.page.title)
> links = [A(p.title, _href=URL('show',args=p.id)) for p in pages]
> return UL(*links)
>
>
> Assume that we would like to search a keyword both in the title and
> the body of the wiki in the following manner:
> 1. The default search searches in the title and body both.
> 2. We have two check boxes with the attribute name set to "title" and
> "body" respectively. Initially both are checked. But the user can
> uncheck one of them to request the application to search only in the
> other field. What is the best way to achieve this?
>
> Specifically, if I add two checkboxes to the search function return
> expression, i.e.:
> INPUT(_type="checkbox", _name="title" ), "Title",
> INPUT(_type="checkbox", _name="body"), "Body",
> how I can check whether they are checked or not from within the
> callback function? I'd like to use these two checkboxes to express
> which fields of the database should be searched.
>
>
>
>
>