In case of form.errors browse for image again

19 views
Skip to first unread message

Annet

unread,
Nov 11, 2020, 11:04:00 AM11/11/20
to web2py-users
When I create a form based on a table that has a field of type upload
to upload an image, I have a problem when one of the other fields
in the table doesn't validate. e.g. a field of type text contains too
may characters.

This form.errors resets the upload field, so I have to browse for
the image again, every time one of the other fields doesn't
validate.

I haven't noticed this behaviour in version 2.14 of web2py, I
am experiencing this behaviour in web2py 2.20.

I hope there's an easy fix, for this is very annoying.


Kind regards,

Annet

Annet

unread,
Nov 11, 2020, 12:11:04 PM11/11/20
to web2py-users
Related to the issue above. I have the following form:

form = SQLFORM.factory(table, db.prm_generic, upload=URL('default', 'download'), buttons=buttons)
...
if form.validate():
        if request.args(0) == 'landingpages':
            if row:
                row.update_record(**db.prm_page._filter_fields(form.vars))
                sub.update_record(**db.prm_generic._filter_fields(form.vars))
            else:
                form.vars.pageid = db.prm_page.insert(**db.prm_page._filter_fields(form.vars))
                db.prm_generic.insert(**db.prm_generic._filter_fields(form.vars))

When I prepopulate the form, the form does not contain the file link and it does not display
the image. It just contains the browse button.

When I submit the form, without adding an image I get the following error:


Ticket ID

127.0.0.1.2020-11-11.18-02-47.b218631d-6dc1-42b1-af58-3f68e9641716

<class 'RuntimeError'> Unable to handle upload Version web2py™
Version 2.20.4-stable+timestamp.2020.05.03.05.18.50
Traceback

The upload field is in sub.update_record(**db.prm_generic._filter_fields(form.vars))

Why doesn't web2py handle this properly?

KInd regards,

Annet


Op woensdag 11 november 2020 om 17:04:00 UTC+1 schreef Annet:
Reply all
Reply to author
Forward
0 new messages