I’m using custom widget in my crud form like this:
{{=form.custom.begin}}
{{if condition:}}
{{=form.custom.widget.field1}}
{{pass}}
{{=form.custom.submit}}
{{=form.custom.end}}
field1 has a relationship to the auth_user table. In my controller I have:
form.custom.widget['field1'] = dropdown
if not condition:
db.admission.field1.readable = db.admission.field1.writable = False
db.admission.field1.default = auth.user.id
I want the widget to show only when the condition is true. If the condition is not true, I want field1 to default to the current logged-in user. But, when the condition is not true, I get the error:
field1 error: value not in database
What am I doing wrong?
Set the
readableandwritableattributes before creating the form — in that case,field1will simply be excluded from the form automatically, and you won’t have to bother with creating a custom form and explicitly including/excluding it.