I’ve made some new modules in my Odoo and now when each form is loading I need to manipulate the created XML elements according to its required model and my arbitrary changes or refer to some specific function for its data validation (I know there are other ways for data validation but I’m curious if it’s possible to be done with jquery functions).
I’ve tried to add an HTML file in the view folder and write a simple script, to begin with, but I’m not sure if it’s the right place or even the right piece of code.
<script>
$(document).ready(function()
{
$("input").keyup(function(event){
console.log('t');
});
});
</script>
I would be glad if anyone could offer some useful answers to my question.
3
Answers
if you want to use jquery or any js library you need to put them in this file under this path /your_app/static/src/js/test.js
and the file should be like this :
and you need to add the assets for this work like that :
For back-office javascript, consider using the "Odoo built-in js library":
In your custom module "my_custom_module":
Create a new file /my_custom_module/static/src/js/my_customization.js:
And declare this asset in the
__manifest__.py
file:You can customize an existing form view using the
js_class
attribute, its value will be the name of an extended form view.To bind a new event to an input, you can customize the form controller and extend the
events
mapping.Example:
1) Extend the form view:
2) Add it to the assets entry in the manifest file
3) Set the js_class attribute on the form view tag