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 it's required model and my arbitrary changes or refer to some specific function for it's 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 a 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 answer for my question.
CodePudding user response:
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 :
$(document).ready(function()
{
$("input").keyup(function(event){
console.log('t');
});
});
and you need to add the assets for this work like that :
'assets': {'web.assets_qweb': ['/your_app/static/src/js/test.js']} #path of the file
this for jquery not for building js model in odoo
CodePudding user response:
For backoffice jsvascript, 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:
odoo.define('my_custom_module.switch_to_gantt', function(require) {
"use strict";
var core = require('web.core');
var _t = core._t;
var AbstractController = require('web.AbstractController');
AbstractController.include({
/**
* Original : Intercepts the 'switch_view' event to add the controllerID into the data, and lets the event bubble up.
* Included : On switching from Kanban to Gantt view : Remove all the GroupBy Filters because it caused Error
*/
_onSwitchView: function (ev) {
console.log(ev.data.view_type);
//debugger;
/* only on the specific view : gantt: */
if(ev.data.view_type == 'gantt')
{
/* only on the specific model : event.event: */
if(ev.target.modelName == 'event.event')
$('.o_searchview .o_facet_remove').click();
}
this._super.apply(this, arguments);
},
});
});
And declare this assets in the __manifest__.py
file:
'assets': {'web.assets_qweb': ['/my_custom_module/static/src/js/my_customization.js']}