我有一个基本的表格和架构..
class NewSchema(colander.MappingSchema):
name = colander.SchemaNode(colander.String(),
widget=text_input)
schema = NewSchema()
myform = Form(schema, buttons=('submit'))
现在这个工作正常,但我想将自定义css类传递给提交按钮,我希望todo:
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>
答案 0 :(得分:2)
你的第一个代码示例不起作用,第二个代码示例在正确的轨道上,但可能在变形按钮类名中有拼写错误。把你和我的比较。你几乎得到它,继续努力。
根据API docs传递一系列字符串或一系列按钮对象。
按钮
一系列字符串或deform.form.Button对象 表示将放置在底部的提交按钮 形成。如果序列中传递了任何字符串,则将其转换为 deform.form.Button对象。
因此,我创建了一个带有应用CSS类的单个按钮,并在创建表单时将其传递给参数buttons
。此示例使用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将其呈现为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>