I created the form in Odoo XML file. When I click to submit the form that same time both input box value does not get in my script.js file. I want to get the input box field value from XML file to Odoo javascript file.
How do I get the input value from XML to JS file?
example.xml:
<template id="example_page" name="Example page" page="True">
<tt-call="website.layout">
<tt-name="DemoTemplate">
<divclass="oe_structure">
<divclass="container">
<formtarget="_self"action=""method="post"id="test_form">
Value of A: <inputtype="text"name="num_a"class="num_A"/><br/>
Value of B: <inputtype="text"name="num_b"class="num_B"/><br/>
Total Value: <input type="text" name="total" class="total" readonly="True"/><br/>
<button type="button" name="button" class="my-button">
<a href="/example" class="btn btn-info">Submit</a>
</button>
</form>
</div>
</div>
</t>
</t>
</template>
Script.js file:
$('#test_form').on('click', 'button.my_button', function(e) {
e.preventDefault();
var num_A = parseInt($("input[name='num_a']").val());
var num_B= parseInt($("input[name='num_b']").val());
console.log('hello');
console.log('num_A ');
console.log('num_B');
ajax.jsonRpc('/my_url/some_url', 'call', {'a': num_A, 'b': num_B})
.then(function(result){
console.log(result);
var output_data=result['total'];
console.log(output_data);
$("#total").html(output_data);
});
});
example.py:
@http.route(['/my_url/some_url'], type='json', auth="public", website=True)
def some_url(self, **arg):
#Fetch input json data sent from js
print "Welcome to JSON function"
a = arg.get('a')
b = arg.get('b');
total_sum = a + b
res={'total':str(total_sum)}
print res
return res
I want to set the total value in my input box how can I achieve it.