Thanks, Anthony.

1. I thought f.name gives the name as <table>.<field> but for the hidden 
fields and form1.element, the field name alone is required. I will make a 
note of it.

2. hidden is included to make sure that the update back end operation does 
not make those fields as NULL. Not sure if the below alternatives will 
work: (a) using 'readonly' attribute so that the values go to the back end 
- but does it happen in all the browsers? (b) may be we can remove the 
disabled attribute just before submitting the form?)

3. I missed explaining r. r is the record from the database containing the 
values for all the selected record and I needed to set them as the values 
of the hidden field. r has been fetched before the below code in the 
function.

4. Simpler codes - noted and thanks a lot for the simplification.

Sundar
=========================================================================

On Tuesday, November 29, 2016 at 9:32:39 PM UTC+5:30, Anthony wrote:
>
> On Tuesday, November 29, 2016 at 8:52:07 AM UTC-5, Sundar wrote:
>>
>> Yes- it looks very bad. I think the below method will work. (Let me know 
>> if you need any elaboration)
>>
>> rofields = [db.<table>.field1, .....]
>> hidden = {} 
>> for f in rofields:
>> fname = str(f).split('.')[1]
>> hidden[fname] = r[fname]
>> form1 = SQLFORM(db.<table>, record=<recid> , showid=True, hidden=hidden)
>>
>
> Note, to get the name of a field, just do field.name. Also, not sure why 
> the hidden fields (SQLFORM won't do anything with their contents), and I 
> don't see "r" defined anywhere.
>
> Some simpler code to disable the form fields:
>
>     [form1.element(_name=f.name).update(_disabled=True) for f in rofields]
>
> An alternative approach is to change the widgets associated with read-only 
> fields:
>
> for field in db.mytable:
>     if field.readable and not field.writable:
>         field.widget = lambda f, v: SQLFORM.widgets[field.type].widget(f, 
> v, _disabled=True)
> form = SQLFORM(db.mytable, record).process()
>
> Anthony
>

-- 
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 the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to