readonly field only in SQLFORgrid edit page if field is not empty

43 views
Skip to first unread message

Mike Constabel

unread,
May 26, 2016, 5:46:45 AM5/26/16
to web2py-users
Hello,

I try to find a solutiuon for a hopefully simple problem.

Example:

db.define_table("foobar",
     
Field("uuid", "string"),
     
Field("text", "string"),
     
Field('created_on', "datetime", default=request.now))

def list_order_type():
    form
= SQLFORM.grid(db.foobar)
   
return dict(form=form)

I need that in the edit page of the grid the field "text" is readonly if the field "text" is not empty and the "created_on" timestamp id older than an hour.

Where and how can I set the db.foobar.text.writable = False?

I can use request.args(1) = 'edit', but how can I then take the row, test it and set the writable to false?

I don't want to validate after sending the form. The input field should be initially readonly.


Regards,
Mike

Val K

unread,
May 26, 2016, 2:45:17 PM5/26/16
to web...@googlegroups.com
Where and how can I set the db.foobar.text.writable = False?
      - before SQLFORM.grid()


I can use request.args(1) = 'edit', but how can I then take the row, test it and set the writable to false?
    as I remember if request.args(1) == 'edit' then  request.args(2) == id of the row to edit

Anthony

unread,
May 27, 2016, 12:48:31 AM5/27/16
to web2py-users
def list_order_type():
   
if 'edit' in request.args:
        record
= db.foobar(request.args(-1, cast=int))
        older_than_an_hour
=
record.created_on < request.now - datetime.timedelta(hours=1)
        db
.foobar.text.writable = not (record.text and older_than_an_hour)
    form
= SQLFORM.grid(db.foobar)
   
return dict(form=form)

Anthony

Mike Constabel

unread,
May 28, 2016, 4:10:13 AM5/28/16
to web2py-users


Am Freitag, 27. Mai 2016 06:48:31 UTC+2 schrieb Anthony:
def list_order_type():
   
if 'edit' in request.args:
        record
= db.foobar(request.args(-1, cast=int))
        older_than_an_hour
=
record.created_on < request.now - datetime.timedelta(hours=1)
        db
.foobar.text.writable = not (record.text and older_than_an_hour)
    form
= SQLFORM.grid(db.foobar)
   
return dict(form=form)

Thank you Anthony, this works perfectly.

Also thank you Val.

Regards,
Mike

Reply all
Reply to author
Forward
0 new messages