Odoo 12:输入必需的验证在门户模板中不起作用
Odoo 12: Input Required validation not working in portal template
我正在尝试在 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=""
、required
、use required="1"
、required="required"
和none。任何想法都会有所帮助。我必须对几个字段进行一些类型转换,如果字段未填充,则会抛出错误。
编辑:我也试过 data-is-required="true"
像收单方表格一样。
我将 <script type="text/javascript" src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/jquery.validate.min.js"></script>
导入到前端资产中,并在表单后添加以下内容以验证它。之后,它只是向 .error class 添加一些 css 来改变颜色,一切都很好!
<script>
("#addRequestLine").validate();
</script>
我正在尝试在 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=""
、required
、use required="1"
、required="required"
和none。任何想法都会有所帮助。我必须对几个字段进行一些类型转换,如果字段未填充,则会抛出错误。
编辑:我也试过 data-is-required="true"
像收单方表格一样。
我将 <script type="text/javascript" src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/jquery.validate.min.js"></script>
导入到前端资产中,并在表单后添加以下内容以验证它。之后,它只是向 .error class 添加一些 css 来改变颜色,一切都很好!
<script>
("#addRequestLine").validate();
</script>