Question

I have a basic form and schema..

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

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

Now this works fine, however I want to pass a custom css class to the submit button, I would expect todo:

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

But this doesn't work, how can I pass this class attribute to a button like this?

EDIT: I have also tried:

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

Which renders the html

<div class="actions">

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

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

</div>

No correct solution

OTHER TIPS

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top