开发者

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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜