SmartGrid Add make a Fld Readonly

55 views
Skip to first unread message

Dan Kozlowski

unread,
Mar 14, 2014, 10:54:28 PM3/14/14
to web...@googlegroups.com
Can someone tell me how within a smartgrids I can make a Fld readonly  on the add and update ?

I have tried the following in the controller and it does not work.

db.clients.writeable=False

黄祥

unread,
Mar 14, 2014, 11:11:51 PM3/14/14
to web...@googlegroups.com
i think you can achieve it using conditional for that.
e.g.
write_in_form = 'add' in request.args or 'edit' in request.args

db.clients.writeable = not write_in_form 

best regards,
stifan

Dan Kozlowski

unread,
Mar 17, 2014, 4:44:42 PM3/17/14
to web...@googlegroups.com
This does not seem to work. Maybe I am asking wrong. I have 2 date fields that get updated from a batch process so I need to restrict them from input on the create and edit form.

Thanks
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/UDGny-3tKq4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

黄祥

unread,
Mar 17, 2014, 5:16:07 PM3/17/14
to web...@googlegroups.com
i'm sorry, my bad :
# check if new or edit is in args (url)
write_in_form = 'new' in request.args or 'edit' in request.args

db.table_name.date_field_1.writeable = not write_in_form 
db.table_name.date_field_2.writeable = not write_in_form 

or another way around
# check if new or edit is in args (url)
write_in_form = 'new' in request.args or 'edit' in request.args

if write_in_form :
    db.table_name.date_field_1.writeable = False 
    db.table_name.date_field_2.writeable = False

best regards,
stifan

Dan Kozlowski

unread,
Mar 17, 2014, 5:59:28 PM3/17/14
to web...@googlegroups.com
I see what you are doing but still does not work. My code is below. Could I have my code in the wrong location ?


def clients():
    write_in_form = 'new' in request.args or 'edit' in request.args
    if write_in_form:
     db.clients.add_date.writeable=False
    ##db.clients.add_date.readable=True
    ##db.clients.add_date.writeable=False
    ##db.history.editable = False,
    ##db.history.editable=False,
   
    grid=SQLFORM.smartgrid(db.clients, onupdate=updateclient,oncreate=createclient, user_signature=False, editable = dict(clients=True, history=False), deletable = dict(clients=True, history=False), create = dict(clients=True, history=False),fields=[db.clients.client_name,db.clients.line_of_business,db.contacts.id_contact_type,db.contacts.contact_name, db.history.client_id_dc,db.history.add_date, db.history.encryption_type,db.history.out_filename])
    return locals()


--

黄祥

unread,
Mar 17, 2014, 7:39:28 PM3/17/14
to web...@googlegroups.com
had you already try to simplify or minimalist your app first?
e.g.
def clients():
    write_in_form_new = 'new' in request.args
    if write_in_form_new:
db.clients.add_date.writeable = False
   
    grid = SQLFORM.smartgrid(db.clients)
    return locals()

best regards,
stifan

Dan Kozlowski

unread,
Mar 17, 2014, 10:36:59 PM3/17/14
to web...@googlegroups.com
I am getting the same result with a minimalist controller. The field still takes a date and updates. Do you think that is a bug or something that can not be done ?

Dan Kozlowski

unread,
Mar 18, 2014, 12:46:34 PM3/18/14
to web...@googlegroups.com
I found the problem after hours of testing different things. It was my mistake. I was using  writeable when it should have been writable. Works perfect now.

Thanks for your help



On 03/17/2014 06:39 PM, 黄祥 wrote:
Reply all
Reply to author
Forward
0 new messages