Adding a button in z3c.form crud

Hi,
I'd want to add another action to the standard two "apply changes" and "delete" actions of a z3c.form crud.

I seems that if I declare my editform_factory with my action button only, the rendered curd form forgets the two defaults actions.

Can I avoid this without cutting and pasting handle_delete and handle_edit actions from crud.EditForm in my editform_factory class?

Here is my code.

from plone.z3cform.crud import crud
from z3c.form import form, field, button

class SimpeEditForm(crud.EditForm):
    @button.buttonAndHandler(_(u'Disable'),
                             name='disable',
                             condition=lambda form: form.context.update_schema)
    def handle_disable(self, action):
        success = _(u"Successfully disabled")
        status = no_changes = _(u"No changes made.")
        selected = self.selected_items()
        if selected:
            # my logic ...

class MainForm(crud.CrudForm):
    update_schema = field.Fields(ISimpleEntry).omit('uid')
    view_schema = field.Fields(ISimpleEntry).select('uid')
    addform_factory= crud.NullForm
    editform_factory = SimpeEditForm
    
    # [...get, add, remove stuff...]

In this way the crud form is rendered with only my disable action button although SimpleEditForm is crud.EditForm based.

thanks for any help.
alessandro.

This should work

class SimpeEditForm(crud.EditForm):
    buttons = crud.EditForm.buttons.copy()
    handlers = crud.EditForm.handlers.copy()
2 Likes

Thanks! it works perfectly :slight_smile:

Plone Foundation Code of Conduct