Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a css class to a z3c.form button

I want to add the css class allowMultiSubmit to a zrc.form button to avoid multi-submit alert. The button is defined like this:

from z3c.form import form
from plone.app.z3cform.layout import wrap_form

class MyForm(form.Form):    
    ...
    @button.buttonAndHandler(_(u"Search"))
    def handleSearch(self, action): 
        ...

MyWrappedFormView = wrap_form(MyForm)

The result that I want to achieve is this:

<input id="form-buttons-search"
       class="submit-widget button-field allowMultiSubmit"
       type="submit"
       value="Search"
       name="form.buttons.search">

There must be an easy way but I can't figure out how.

like image 263
Giacomo Spettoli Avatar asked Sep 30 '11 11:09

Giacomo Spettoli


1 Answers

You can override the updateActions method of your z3c.form class and use the addClass method to add a css class to your button:

from z3c.form import form
from plone.app.z3cform.layout import wrap_form

class MyForm(form.Form):    
    ...
    @button.buttonAndHandler(_(u"Search"))
    def handleSearch(self, action): 
        ...

    def updateActions(self):
        super(MyForm, self).updateActions()
        self.actions['submit'].addClass("allowMultiSubmit")

MyWrappedFormView = wrap_form(MyForm)
like image 103
tisto Avatar answered Nov 13 '22 21:11

tisto