Try setting the field's default instead: db.dog.owner.default = 10
On Apr 6, 3:11 pm, zip <zip...@gmail.com> wrote: > I am using an AutocompleteWidget with and id_field set and would like > to prepopulate the data for this widget. > > Say I have the following tables: > Person with id and name fields > Dog with id, name and owner fields > > I have the following line to setup the widget for dog.owner: > db.dog.owner.widget = SQLFORM.widgets.autocomplete(request, > db.person.name, limitby=(0,5), auth=auth, min_length=2, > id_field=db.person.id) > > My controller: > form = SQLFORM(db.dog, fields=fields, formstyle='table3cols', > submit_button='Add', comments=False) > > form.vars.owner = 10 > > form.accepts(request.vars, session) > > The above sets the hidden field in the form to the proper owner > (person.id) but the visible input box is blank. So I also added the > following line to try to get SQLFORM to put a value into the input box > and it did: > form.vars._autocomplete_owner_aux = "Fred" > > However, when I submit the form I get an error from SQLFORM.accepts() > because _autocomplete_owner_aux is not a field in the table dog. The > error comes from the following line 1201 from sqlhtml.py, self.vars.id > = self.table.insert(**fields). Shouldn't this call filter the fields > dictionary to remove any fields not in the table? Is there a better > way of prepopulating the autocomplete widget?