On Nov 1, 11:11 pm, Omi Chiba <[email protected]> wrote:
> Thank you for understanding me :)
> I tried but this code will set the default value if the field exist on
> the view.
>
> I made a simple example. I don't want to show field2 so it's excluded
> in view using custom form but want to store the value like 'BBB' or
> 'CCC' before it's inserted into table. This code just leave field2
> blank...
>
> model
> ------------------------
> db.define_table('mytable',
>     Field('field1'),
>     Field('field2'))
>
> controller
> ------------------------
> def index():
>     form = SQLFORM(db.mytable)
>
>     form.vars.field2 = 'BBB'

This should work to pre-populate the value of field2 with 'BBB' but it
seems to be broken in 1.99.2

>
>     if form.process().accepted:
>         form.vars.field2 = 'CCC'

this has no effect, field2 will not be set to 'CCC' in the DB, the
insert has already been done at this point so field2 will be 'BBB' (if
it wasn't broken).
To change it you have to use onvalidation, see the example in the
book.

>         session.flash = 'form accepted'
>         redirect(URL('index'))
>     elif form.errors:
>         response.flash = 'form has errors'
>     return dict(form=form)
>
> view
> ------------------------
> {{extend 'layout.html'}}
>
> {{=form.custom.begin}}
> Field1: {{=form.custom.widget.field1}}
> {{=form.custom.submit}}
> {{=form.custom.end}}
>
> On Nov 1, 6:58 pm, pbreit <[email protected]> wrote:
>
>
>
>
>
>
>
> > I believe in your controller, before form.process() (or form.accepts),
> > include:
>
> > form.vars.FFTSCD = 'aaa'

Reply via email to