Made some progress -- got a the field not showing to user yet visible in
the onvalidation function.
Now, a new problem. When I change the value of the hidden field in the
onvalidate function, it doesn't get written to the database. The value
remains whatever was passed as the default in the SQLFORM(hidden=dict())
The code
db.define_table('person',
Field('name', 'string'),
Field('hidden', 'string'))
def index():
form = SQLFORM(db.person, fields=['name'], hidden=dict(hidden="Default
hidden text"))
form.vars.hidden = request.vars.
if form.process(onvalidation=validate_form).accepted:
pass
return dict(form=form)
def validate_form(form):
*form.vars.hidden = "Changed hidden text" #Never gets written to
database*
form.accepted = True
In the code above the field db.person.hidden always receives the value
"Default hidden text". What needs to change to get it to what it is set
to in validate_form, "Changed hidden text"?
On Friday, February 7, 2014 8:43:19 AM UTC-6, A36_Marty wrote:
>
> I'm stumped. Have tried this with the grid, custom forms, etc.
>
> Could someone advise how to achieve the questions highlighted below - or -
> if it can't be done with a grid, how to achieve it?
>
> db.define_table('table',
> Field('field_hidden', 'string'),
> Field('field_not_hidden', 'string'))
>
> *def index():*
>
> Question: Code to hide 'field_hidden' to user but still make it
> available in the validate_grid function?
>
> grid = SQLFORM.grid(table, onvalidation=validate_grid)
>
> return grid
>
> *def validate_grid(form):*
>
> Question: Code to be able to modify 'field_hidden' here & have it
> written to the database?
>
> form.accepted = True
>
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.