You cannot make a field not writable conditionally. Because if the field is 
writable it shows in the form. This is before you know the value of the 
other field.

Conditionally you can remove the field from form.post_vars.

On Monday, 23 June 2014 12:26:04 UTC-5, 98u...@gmail.com wrote:
>
> I did what you suggested but the calls to:
>
> db.owner.own_end_date.writable = False # not writable
> db.owner.own_end_date.readable = False # do not show is at all!
>
> are effective only if executed before the call to form = 
> SQLFORM.smartgrid(db.owner, ...
> When executed after, have no effect.
> I want to make db.owner.own_end_date not writeable conditionally:
>    ...
>    ...
>    if ((len(request.args)>1) and (request.args(1)=='edit')):
>         if (form.element('input',_name='own_end_date')['_value']!=''):
>             db.owner.own_end_date.writable=False # <----- no effect
>     ...
>     ...
>
> If the edited record contains a date value in that field then user must 
> not change it. How can I make that field not writeable in such a case?
> Thanks
>
> On Monday, June 23, 2014 1:00:05 AM UTC-4, 98u...@gmail.com wrote:
>>
>> Why readonly elements (select and date field) of a form respond to clicks 
>> and allow for changes and can be submitted? They look grayed out as if 
>> readonly but when I click on date field the date picker appears and works 
>> as it shoud also the select option is grayed out but it offers a list to 
>> choose an option and the form can be submitted with these changed values 
>> even though this is not intended.
>> #this is the model
>>
>> db.define_table('owner',
>>                 Field('own_cust_fk','reference 
>> customer',label='Customer'),
>>                 Field('own_veh_fk','reference vehicle',label='Vehicle'),
>>                 Field('own_plate','string',label='Plate'),
>>                 Field('own_comment','string',label='Comment'),
>>                 Field('own_start_date','date',default=now,label='Start 
>> date'),
>>                 
>> Field('own_end_date','date',default=None,label='Terminated'),
>>                 migrate='owner.table',format='%(own_plate)s 
>> %(own_cust_fk)s',
>>                 plural='Owner'
>>                 )
>>
>>
>> def index():
>>
>>     ...
>>     ...
>>
>>     form = SQLFORM.smartgrid(db.owner,
>>                              fields=fields,
>>                              headers=headers,
>>                              paginate=all,
>>                              details=True,
>>                              editable=True,
>>                              deletable=False,
>>                              create=False,
>>                              showbuttontext=False,
>>                              maxtextlength=40,
>>                              maxtextlengths=maxtextlengths,
>>                              buttons_placement = 'left',
>>                              )
>>     ...
>>     ...
>>
>>     if ((len(request.args)>1) and (request.args(1)=='edit')):
>>             form.element('select',_name='own_cust_fk')['_readonly']='True'
>>             form.element('input',_name='own_end_date')['_readonly']='True'
>>     ...
>>     ...
>>     return dict(form=form)
>>
>>
>>
>> Any help would be appreciated!
>> 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 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