[Product-Developers] dexterity [newbie] : how to disable a Field widget

David Glick davidglick at groundwire.org
Mon Nov 14 00:28:39 UTC 2011


On 11/12/11 2:49 PM, Asko Soukka wrote:
> T. Kim Nguyen wrote:
>> Hi David - we've had that particular use case a few times here: we want to populate a student ID field but don't want the student to be able to change it, while a staff member filling out the object on behalf of the student might need to change it.
> Hi,
>
> can't this be achieved by using write_permission and read_permission
> -form schema hints from plone.directives.form?
>
> class MySchema(form.Schema):
>     form.write_permission(field1='some.staffonlypermission')
>     field1 = ...
>
That is also an option, but doesn't quite meet the use case that was 
described (if the user lacks the write permission and the form is in 
input mode, then the field will not show up at all, rather than showing 
up disabled).

Most of the z3c.form widgets appear to support a 'disabled' property; we 
just don't have a way to set it from a Dexterity model at this point. So 
one could do in a custom form:

def updateWidgets(self):
     self.widgets['field1'].disabled = True

David


----------		
David Glick
 Web Developer
 davidglick at groundwireconsulting.com
 206.286.1235x32

Groundwire Consulting is here.

http://groundwire.org/about/FAQ-gw-consulting




More information about the Product-Developers mailing list