如何以金字塔形式呈现按钮

问题描述 投票:0回答:2

我正在与pyramid合作创建网页。

根据文档中的示例(随附),我可以将表单架构传递给html模板,并选择表单中的每个字段,然后分别进行呈现。这使我很容易为表单字段设置样式。

但是,该示例未显示如何呈现按钮组件。

在所附示例中,如果我有一个提交按钮,

$ $ = transform.Form(schema,button =('submit',))

我将如何仅渲染html中的按钮,而无需再次重新渲染字段?

enter image description here

更新:

这是我最终使用自定义提交按钮的方式。

<div class="form-group text-center" tal:define="submit form.buttons[0]">
   <button name="submit" type="submit" value="submit" class="btn btn-primary btn-lg btn-block">${submit.title}</button>
</div>
python html forms schema pyramid
2个回答
1
投票

通过form.buttons列表可用的按钮。

这是在默认表单模板(form.render())中呈现按钮的方式

<div class="form-group deform-form-buttons">
    <tal:loop tal:repeat="button form.buttons">
        <button
                tal:define="btn_disposition repeat.button.start and 'btn-primary' or 'btn-default';"
                tal:attributes="disabled button.disabled if button.disabled else None;
                                attributes|button.attributes|{};"
                id="${formid+button.name}"
                name="${button.name}"
                type="${button.type}"
                class="btn ${button.css_class or btn_disposition}"
                value="${button.value}"
                tal:condition="button.type != 'link'">
            <span tal:condition="button.icon" class="glyphicon glyphicon-${button.icon}"></span>
            ${button.title}
        </button>
        <a
                tal:define="btn_disposition repeat.button.start and 'btn-primary' or 'btn-default';
                btn_href button.value|''"
                class="btn ${button.css_class or btn_disposition}"
                id="${field.formid + button.name}"
                href="${btn_href}"
                tal:condition="button.type == 'link'">
            <span tal:condition="button.icon" class="glyphicon glyphicon-${button.icon}"></span>
            ${button.title}
        </a>
    </tal:loop>
</div>

1
投票

您在HTML按钮元素中呈现属性。

<button value="{{ form.buttons[0].value|safe }}" name="{{ form.buttons[0].name|safe }}" class="{{ form.buttons[0].css_class|safe }}" type="{{ form.buttons[0].type|safe }}">{{ form.buttons[0].title|safe }}</button>

例如,将呈现表单模式中声明的表单中的第一个按钮。

© www.soinside.com 2019 - 2024. All rights reserved.