sqlhtml changes for sqlform.factory, not nice, 2.15.4 versus 2.18.5

93 views
Skip to first unread message

Awe

unread,
Aug 4, 2021, 12:16:40 PM8/4/21
to web2py-users
we are using sqlform.factory a lot, but the way fields are shown/behave was changed from
2.15.4
fields = [f.name for f in table if  (ignore_rw or f.writable or f.readable) and (readonly or not f.compute)]
to
2.18.5
fields = [f.name for f in table if (ignore_rw or f.writable or (f.readable and f.default)) and not f.compute]

so in 2.15.4 it was no problem to have an edit form with fields like
readable=True, writable=False, default=""
this field having an empty string was shown disabled, great as expected.

in 2.18.5
this field will not be shown anymore, we need to set default=" " like this, which is
not very useful.

Is this a bug or feature, or is there a NEW common way to have empty readonly fields in an
edit form

Many thanks for any help!

Awe

unread,
Sep 30, 2021, 5:04:28 AM9/30/21
to web2py-users
Is anybody out there facing the same problem, wondering about getting no answers...

Jim S

unread,
Oct 2, 2021, 10:26:42 AM10/2/21
to web2py-users
Have you tried with the latest web2py?

I'm assuming the behavior is the same as with 2.18.5.

Have you been able to pinpoint a commit that would have changed this behavior?

-Jim

Awe

unread,
Oct 9, 2021, 5:14:17 PM10/9/21
to web2py-users
Thanks for the answer
I haven't tried the latest version and I hope this behavior doesn't change from version to version..
but. I thought / hoped a web2py developer could explain why this important/central feature was changed and how to deal with it best.

Massimo Di Pierro

unread,
Oct 10, 2021, 12:27:42 AM10/10/21
to web2py-users
Looking at latest version 2.21. The change you mention is only for create forms, not edit forms. It basically say if a field is readable and not writable and has not value, it should not be displayed. It seems the correct behavior to me. Maybe in 1.18 the same logic was incorrectly applied to edit fors as well? Do not remember. Please try the latest.

Awe

unread,
Oct 11, 2021, 5:08:54 AM10/11/21
to web2py-users
Hello Massimo,
thanks for replying.
Maybe I didn't quite understand.
I assumed that when using the Sqlform.factory no "record" is transmitted. This means that the "create" branch is always used in 2.21, 2.18, 2.15.4, independent of "create" or "edit" forms. In my point of view, for sqlform.factory, there is no difference between create / edit. For my purposes, the "old" code
        fields = [f.name for f in table if  (ignore_rw or f.writable or f.readable) and (readonly or not f.compute)]
was correct, cause I want to show a readable Field in an edit form, even when its value is ""
but changing to "f.readable and f.default", when f.default = "", will result in a no show.
Am I wrong?

code, 2.21, 2.18,
if fields is None:
      if not readonly:
            if not record:
            # create form should only show writable fields

                    fields = [f.name for f in table if (ignore_rw or f.writable or (f.readable and f.default)) and not f.compute]
            else:
                   # update form should also show readable fields and computed fields (but in reaodnly mode)
                   fields = [f.name for f in table if (ignore_rw or f.writable or f.readable)]
        else:
               # read only form should show all readable fields
               fields = [f.name for f in table if (ignore_rw or f.readable)]
Reply all
Reply to author
Forward
0 new messages