如何将css类添加到z3c.form按钮

时间:2011-09-30 11:08:26

标签: plone zope z3c.form

我想将css类allowMultiSubmit添加到zrc.form按钮以避免多次提交警报。按钮的定义如下:

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)

我想要达到的结果是:

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

必须是一种简单的方法,但我无法弄清楚如何。

1 个答案:

答案 0 :(得分:9)

您可以覆盖z3c.form类的updateActions方法,并使用addClass方法将css类添加到按钮中:

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)