Odoo 12:输入必需的验证在门户网站模板中不起作用

时间:2019-12-09 19:47:40

标签: xml forms validation odoo-12

我正在尝试在odoo 12的门户模板中创建表单,我想输入一些所需的信息。这是我的表单对话框。除了某些输入中的必需元素之外,带有表单的其他所有内容都按预期工作。

<div role="dialog" class="modal fade" id="wc-modal-new_line" aria-hidden="true">
          <div class="modal-dialog">
            <div class="modal-content">
              <header class="modal-header">
                <h4 class="modal-title">Add Item</h4>
              </header>
              <form method="post" t-attf-action="/my/equipment_requests/#{equipment_request.id}/new_line">
                <input class="d-none" name="csrf_token" t-att-value="request.csrf_token()"/>
                <main class="modal-body">
                  <div class="form-group">
                    <table border="0">
                      <tr>
                        <td><label for="type">Loan Type </label></td>
                        <td>
                          <select name="type">
                            <option value="long">Long Term</option>
                            <option value="short">Short Term</option>
                          </select>
                        </td>
                        <td><label for="vendor_id">Vendor </label></td>
                        <td>
                          <select name="vendor_id">
                            <t t-foreach="vendors" t-as="vendor">
                              <option t-attf-value="#{vendor.id}"><span t-field="vendor.name"/></option>
                            </t>
                          </select>
                        </td>
                      </tr>
                      <tr>
                        <td><label for="product_id">Product </label></td>
                        <td>
                          <select type="selection" name="product_id">
                            <t t-foreach="products" t-as="product">
                              <option t-attf-value="#{product.id}"><span t-field="product.display_name"/></option>
                            </t>
                          </select>
                        </td>
                        <td><label for="name">Description * </label></td>
                        <td><input type="text" name="name" required="required"/></td>
                      </tr>
                      <tr>
                        <td><label for="product_qty">Quantity * </label></td>
                        <td><input type="number" name="product_qty" required="required"/></td>
                        <td><label for="price_unit">Unit Price *</label></td>
                        <td><input type="number" name="price_unit" required="required"/></td>
                      </tr>
                      <tr>
                        <td><label for="reason">Reason * </label></td>
                        <td><input type="text" name="reason" required="required"/></td>
                        <td><label for="web_address">Web Address </label></td>
                        <td><input type="text" name="web_address" placeholder="https://www.moddulu.com"/></td>
                      </tr>
                    </table>
                  </div>
                </main>
                <footer class="modal-footer">
                  <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                  <button type="submit" class="btn btn-primary contract-submit">Add Item</button>
                </footer>
              </form>
            </div>
          </div>
        </div>

我尝试使用use required=""requireduse required="1"required="required",但它们都不起作用。任何想法都会有所帮助。我必须对几个字段进行类型转换,如果不填充字段,则会引发错误。

编辑:我也尝试过data-is-required="true",就像在付款收款人表格中一样。

1 个答案:

答案 0 :(得分:0)

我将<script type="text/javascript" src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/jquery.validate.min.js"></script>导入了前端资产,并在表单后添加了以下内容以对其进行验证。之后,只需在.error类中添加一些CSS即可更改颜色,并且一切正常!

<script>
   ("#addRequestLine").validate();
</script>