1

我有一个基本的表格和架构..

class NewSchema(colander.MappingSchema):
        name = colander.SchemaNode(colander.String(),
            widget=text_input)

schema = NewSchema()
myform = Form(schema, buttons=('submit'))

现在这工作正常,但是我想将自定义 css 类传递给提交按钮,我希望这样做:

schema = PaymentSchema()
myform = Form(schema, buttons=('submit', css_class="someclass"))

但这不起作用,我怎样才能将这个类属性传递给这样的按钮?

编辑:我也试过:

butt = deform_form.Button(name='submita', css_class="test")
schema = PaymentSchema()
myform = Form(schema, buttons=(butt,))

哪个呈现html

<div class="actions">

    <button
        id="deformsubmita"
        name="submita"
        type="submit"
        class="btn btnText submit primaryAction"
        value="submita"

        >
    <span>Submita</span>
    </button>

</div>
4

1 回答 1

2

Your first code example will not work, the second is on the right track, but may have a typo in deform button class name. Compare yours to mine. You almost got it, keep on trying.

According to API docs either pass a sequence of strings or a sequence of button objects.

buttons

A sequence of strings or deform.form.Button objects representing submit buttons that will be placed at the bottom of the form. If any string is passed in the sequence, it is converted to deform.form.Button objects.

Therefore I create a single button with applied CSS class and pass it in a tuple to parameter buttons while creating the form. This example is using deform2.0a2

class WikiViews(object):
    def __init__(self, request):
        self.request = request

    @property
    def wiki_form(self):
        schema = WikiPage()
        submit = deform.Button(name='submit', css_class='red')
        return deform.Form(schema, buttons=(submit,))

    @view_config(route_name='wikipage_add',
             renderer='deform2_demo:templates/wikipage_addedit.pt')
    def wikipage_add(self):
        form = self.wiki_form.render()
        ... 

deform renders this to HTML:

    <form id="deform" method="POST" enctype="multipart/form-data" accept-charset="utf-8" class="deform">

      <fieldset class="deformFormFieldset">   

        <input type="hidden" name="_charset_">
        <input type="hidden" name="__formid__" value="deform">

         <div class="form-group  item-title" title="" id="item-deformField1">    
           <label for="deformField1" class="control-label required" id="req-deformField1">Title</label>    
           <input type="text" name="title" value="" id="deformField1" class=" form-control ">

         </div>

         <!-- removed HTML for more deform fields -->

         <div class="form-group">
           <button id="deformsubmit" name="submit" type="submit" class="btn btn-primary red" value="submit">Submit</button>

         </div>
      </fieldset>

    </form>
于 2014-02-20T11:16:44.563 回答