Behavior of forms with IS_IN_SET

1 view
Skip to first unread message

Mike

unread,
Sep 27, 2008, 3:31:28 PM9/27/08
to web2py Web Framework
Hi Everyone,

I'm not sure if this is the expected behavior or not, but I wasn't
expecting it...

I have a model that uses
requires=IS_IN_SET(['a','b','c'],labels=['AA,'BB','CC']) on on of the
fields. Everything renders in the form fine (I love web2py).

Now-- if I add a default value to the field that has the IS_IN_SET
validator, the form will properly select the default from the drop
down when using a SQLFORM to insert a new record.

BUT if I happen to choose a non-default value from the dropdown AND
the form has another error (lets say you forget to fill in a required
field). The drop down resets to the default instead of staying on the
user selected value. I think this would cause a lot of user
headaches...

My current solution is to omit the default value from the table
definition. In that scenario, the user selected value remains
selected, even if the form has an error. Reordering the list of
options in the validator lets me 'pre-select' a value.


Has anybody else run into this?

Mike

mdipierro

unread,
Sep 27, 2008, 4:46:19 PM9/27/08
to web2py Web Framework
This could be a bug. I will investigate. Thanks for letting us know.

Massimo

DenesL

unread,
Sep 28, 2008, 10:52:43 PM9/28/08
to web2py Web Framework
It is not a bug per se but it would be nice to have forms behave the
way Mike expects them to.
Currently the form components are created during initialization while
form.vars are only available after accepts, so there is no way to
create the components with their values.
Maybe we could create the components during accepts and set the
default to current the value of those form.vars that are not in
form.errors .

DenesL

unread,
Oct 1, 2008, 11:22:09 AM10/1/08
to web2py Web Framework
After some more testing and code tracing I can say:
- The resulting dropdown will have a double selection, one for the
default value (set by SQLFORM __init__) and one for the corresponding
request.vars value (set during accepts) if it is different from the
default.
- It is a bug but not an easily squishable one.
- There is no need to use form.vars as I thought in my previous post,
request.vars has the info.
- The solution might still be to recreate the form components if there
are errors but further testing is required.
Reply all
Reply to author
Forward
0 new messages