[web2py] Ajax question: In a controller, how do I format data by a view so that I can return HTML from the controller back to ajax function?

2011-10-22 Thread Brent Jacobs
Hi all,

I need some help please.

I have a function/controller which is called by ajax calls.  In the
function I want to get some data from a model, format the data into
html, and then return the HTML.

It makes sense that I should be able to pass the model data to a view
and then pass the html from the view back to the ajax function.  I
cant work out how to do this.

This is what I would expect to happen:
Ajax call to controller -- Controller gets data from model --
controller passes data to view -- View does its thing and passes back
HTML to controller (rather than the browser) -- controller returns
the HTML to the ajax call.

Any help on this would be appreciated.  Thanks,


[web2py] Adding radio buttons to customised form in web2py

2011-09-17 Thread Brent Jacobs
I'm trying to display a field as a radio button group in a customised
form.  I want to place each radio button on a different row in a
table.  The problem is when I use `{{=form.custom.selection_type[0]}}
`, the widget is wrapped in unwanted `tr` and `td` tags.

Is there a way to add only the radio input field without the
additional tags? Also, is it possible to have the innerhtml different
from the value of the radio button?

Thanks.

My view:

{{extend 'layout.html'}}
{{=form.custom.begin}}
table
  tr
td {{=form.custom.selection_type[0]}}:/td
td {{=form.custom.widget.biller_list}}/td
  /tr
  tr
td {{=form.custom.widget.selection_type[1]}}:/td
td {{=form.custom.widget.biller_code}}/td
  /tr
/table
{{=form.custom.end}}

Example of what's happening in the html source code:

table
  tr
td trtdinput name=selection_type type=radio
value=From my biller list /From my biller list/td/tr:/td
...
  /tr
...
/table

My model:

db.define_table('payment_bpay_step1',
Field('selection_type', 'list:string'),
Field('biller_list', db.biller, notnull=True),
Field('biller_code'),
Field('biller_name'))
db.payment_bpay_step1.selection_type.requires = IS_IN_SET(('From
my biller list', 'Search by biller code', 'Search by biller name'))
db.payment_bpay_step1.selection_type.widget =
SQLFORM.widgets.radio.widget