Handler not evaluated if button.condition is False
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
z3c.form |
Won't Fix
|
Undecided
|
Unassigned |
Bug Description
A form.Edit Form return to itself.
A button has a condition the changes its visibility in
dependecy to the actual request (get parameter).
If the button is visible and gets a hit the handler is not called
if the new request leads to a condition that hides the button.
The following code registers a button and Handler with a condition applied.
...
def showApply(self):
return ( self.request.
@button.
def handleCommit(self, action):
self.xxx = 1
...
z3c.form.button.py reads:
...
def update(self)
...
for name, button in self.form.
# Step 1: Only create an action for the button, if the condition is
# fulfilled.
if button.condition is not None and not button.
...
The action is only evaluated if the button condition is true.
Since in my case the condition depends on the actual request the
handler associated with the Button is only excecuted if the Request
leads to a condition that is true.
Yes, those are tricky cases, but it is not z3c.form's fault. You simply have to make your ``showApply()`` method smarter and take your additional condition into account. I have encountered these chicken-and-egg problems many times when writing forms.
In general, I write the condition against the model data not the request. If the model gets updated during the action, I commonly simply re-update the actions, which is allowed. In general, it is sometimes necessary to update widgets and actions multiple times during the update process. (This is a lot like needing to render LaTeX documents multiple times to get page references correctly.)