Search code examples
plonedexterity

Plone- In a dexterity.EditForm why is attempting to disable a widget causing a ConstraintNotSatisfied error?


I'm trying to disable a widget in a dexterity.EditForm, but I'm getting an error .

Here is a part of my interface class with the particular widget I want to disable

class IRestaurant(IPlace):

    restaurant_code = schema.TextLine(title=_(u""),
                                      required=False,
                        )

IPlace is a form.Schema that IRestaurant inherits from. (from plone.directives)

Here is the code I for the dexterity.EditForm class:

class Edit(dexterity.EditForm):
    grok.context(IRestaurant)

    def updateWidgets(self):
        super(Edit, self).updateWidgets()
        self.widgets['restaurant_code'].disabled = True

When I go to the edit form, I get an error:

ConstraintNotSatisfied: True

Why is this error occurring and how can I fix this?

Also, the version of Plone I am using is Plone 4.3.5.

Edit: When I tried printing the type of object that self.widgets['restaurant_code'].disabled was, it said it was a NoneType object.


Solution

  • You might have better luck using the mode property.

    Try something like this:

    from z3c.form.interfaces import HIDDEN_MODE
    
    def updateWidgets(self):
        super(Edit, self).updateWidgets()
        self.widgets['restaurant_code'].mode = HIDDEN_MODE