【问题标题】:How to make a Horizontal form with deform 2?如何使用变形 2 制作水平形式?
【发布时间】:2014-05-30 12:34:16
【问题描述】:

我正在使用deform 2 和Bootstrap 3 一起渲染一些表单,我想创建一个水平表单,如图here,但是demo-site 上的所有示例都不是水平表单的示例(带有输入元素旁边的标签)。

我尝试过使用form_class="form-horizontal"bootstrap_form_style="form-horizontal"(deform_bootstrap)。使用上述方法时,它确实添加了类form-horizontal,但是我不想只是向表单元素添加一个类。

如何将其余的类名添加到表单的其余部分以使其成为水平表单,就像 bootstrap site 上的一样?

【问题讨论】:

标签: python css forms twitter-bootstrap deform


【解决方案1】:

我想通了,在变形模板中(我重写了它们)我做到了:

ma​​pping_item.pt:

<div tal:define="error_class error_class|field.widget.error_class;
                 description description|field.description;
                 title title|field.title;
                 oid oid|field.oid;
                 hidden hidden|field.widget.hidden;
                 category category|field.widget.category;
                 structural hidden or category == 'structural';
                 required required|field.required;"
     class="form-group  ${field.error and 'has-error' or ''} ${field.widget.item_css_class or ''}"
     title="${description}"
     id="item-${oid}"
     tal:omit-tag="structural"
     i18n:domain="deform">
  <!-- <div class="col-sm-12"> -->


  <label for="${oid}"
         class="control-label col-sm-3 col-md-3 ${required and 'required' or ''}"
         tal:condition="not structural"
         id="req-${oid}"
         >
    ${title}
  </label>
<div class="col-sm-9 col-md-9">
  <div tal:define="input_prepend field.widget.input_prepend | None;
                   input_append field.widget.input_append  | None"
       tal:omit-tag="not (input_prepend or input_append)"
       class="input-group">
    <span class="input-group-addon"
          tal:condition="input_prepend">${input_prepend}</span
    ><span tal:replace="structure field.serialize(cstruct).strip()"
    /><span class="input-group-addon"
            tal:condition="input_append">${input_append}</span>
  </div>

  <p class="help-block"
     tal:define="errstr 'error-%s' % field.oid"
     tal:repeat="msg field.error.messages()"
     i18n:translate=""
     tal:attributes="id repeat.msg.index==0 and errstr or
     ('%s-%s' % (errstr, repeat.msg.index))"
     tal:condition="field.error and not field.widget.hidden and not field.typ.__class__.__name__=='Mapping'">
    ${msg}
  </p>

   <p tal:condition="field.description and not field.widget.hidden"
     class="help-block" >
    ${field.description}
  </p>

  </div>
</div>

通知在label我加了col-sm-3 col-md-3
我还添加了一个带有类的&lt;div&gt;class="col-sm-9 col-md-9"

这使得项目,即标签+输入“水平”(显示在同一行):

form.pt,在我添加的表单标签中:

class="deform ${field.bootstrap_form_style | 'form-horizontal'}

我在定义表单布局时也这样做:

agent = colander.SchemaNode(
    colander.String(),
    validator=agent_validator,
    widget=widget.AutocompleteInputWidget(
        size=40,
        style="width: 300px",
        min_length=3,
        values=url,
        css_class="form-control"
        ),
    title="Agent*")

我希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2022-12-06
    • 2015-03-06
    • 2018-03-04
    • 1970-01-01
    • 2011-04-14
    • 1970-01-01
    • 1970-01-01
    • 2011-12-01
    • 1970-01-01
    相关资源
    最近更新 更多