Handler not evaluated if button.condition is False

Bug #612663 reported by volker.jaenisch
6
This bug affects 1 person
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.get('from_workflow') == '1' )

    @button.buttonAndHandler( u'Commit', condition=lambda form: form.showApply())
    def handleCommit(self, action):
        self.xxx = 1
...

z3c.form.button.py reads:
...
def update(self)
...
        for name, button in self.form.buttons.items():
            # Step 1: Only create an action for the button, if the condition is
            # fulfilled.
            if button.condition is not None and not button.condition(self.form):
                continue
...
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.

Revision history for this message
Stephan Richter (srichter) wrote :

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.)

Changed in z3c.form:
status: New → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.