在自定义模板(网站)中,我添加了输入标记。我想获取此标记的值以便将其发送到控制器。通过将此添加到网址,但我始终得到“无”#39;回来。
<template id="InputTemp" inherit_id="website_sale.cart">
<xpath expr="//div[@id='right_column']" position="after">
<div class="col-lg-3 col-lg-offset-1 col-sm-3 col-md-3 text-muted" id="inputform">
<h3>Please enter value:</h3>
<label class="control-label" for="waardebon">Value</label>
<input type="text" name="value_input" class="form-control"/>
<a t-attf-href="/cart/#{str(value_input)}" class="btn btn-primary btn-lg mt8">Submit</a>
</div>
</xpath>
</template>
答案 0 :(得分:2)
在将任何数据输入表单字段之前,将呈现t-attf-href。要按照您的方式执行此操作,您需要使用javascript更新您的href。在odoo9中,您需要使用requirejs语法来加载适当的库以向控制器运行发布请求。如果您只是使用get请求,则以下内容适用于您的示例。
<template id="InputTemp" inherit_id="website_sale.cart">
<xpath expr="//div[@id='right_column']" position="after">
<div class="col-lg-3 col-lg-offset-1 col-sm-3 col-md-3 text-muted" id="inputform">
<h3>Please enter value:</h3>
<label class="control-label" for="waardebon">Value</label>
<input type="text" name="value_input" id="value_input" class="form-control"/>
<a id='submit-btn' t-attf-href="#" class="btn btn-primary btn-lg mt8">Submit</a>
<script>
var value_input = document.getElementById('value_input');
var submit_button = document.getElementById('submit-btn');
value_input.addEventListener('input', function(){
submit_button.href = "/cart/?input_value=" + value_input.value;
});
</script>
</div>
</xpath>
</template>
这是一个示例控制器。
@http.route('/cart/', auth='public', website=True)
def get_cart_vals(self, **kw):
# YOUR VARIABLE value_input SHOULD BE AVAILABLE IN THE QUERY STRING
query_string = request.httprequest.query_string
# PROCESS DATA AND LOAD THE RESPONSE TO THE USER OR REDIRECT HERE
答案 1 :(得分:0)
template.xml
<openerp>
<data>
<template id="test_form">
<t t-call="website.layout">
<script type="text/javascript" src="/test_workflow/static/src/js/jquery.min.js"></script>
<body>
<div class="container">
<div class="page">
<div class="row">
<form>
<input type="date" name="start_date"/>
<input type="checkbox" name="critical" value="Critical"></input>
<input type="checkbox" name="minor" value="Minor"></input>
<input type="submit" value="Submit" ></input>
</form>
</div>
</div>
</div>
</body>
</t>
</template>
</data>
</openerp>
controller.py
class test_controller(http.Controller):
@http.route('/test1/<self_id>', auth='user', website=True)
def test1(self,self_id,**kw):
print('>>>>>>>>>>>>>>test123', kw)
return http.request.render('test_workflow.test_form', {
'num_list':[1,2,3,4,5,6,7],
})
参考:http://learnopenerp.blogspot.com/2018/06/odoo-get-web-form-template-value-in-controller.html