I want to call a javascript on a button click, I tried a lot of examples and it didn't work. The button needs a name and the associated functions run on the server sides, I want the event to run on the client side only.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- إدارة علاقات العملاء
- e-Commerce
- المحاسبة
- المخزون
- PoS
- Project
- MRP
لقد تم الإبلاغ عن هذا السؤال
Here is the solution using owl framework https://github.com/binyama/button_to_call_js_odoo.git
To call a JavaScript function when a button is clicked in Odoo, you can use the onclick attribute of the button element and specify the name of the function you want to call. For example:
You can also use the qweb template engine to define the button in your XML file and bind the onclick event to a function in your JavaScript file. For example:
Then in your JavaScript file, you can define the myFunction function:
Copy code
odoo.define('my_module.my_javascript_file', function (require) {
"use strict";
var core = require('web.core');
var _t = core._t;
function myFunction() {
console.log("Button clicked!");
}
return {
myFunction: myFunction,
};
});
You can also use the $.Event() function to trigger the button click event in your JavaScript code:
Copy code
$('button').trigger('click');
Keep in mind that you need to make sure that your JavaScript file is loaded on the page before you try to call any of the functions defined in it. You can do this by adding a dependency on your JavaScript file in the depends attribute of your module's manifest file
I can't see the pictures you upload can you do it again?
هل أعجبك النقاش؟ لا تكن مستمعاً فقط. شاركنا!
أنشئ حساباً اليوم لتستمتع بالخصائص الحصرية، وتفاعل مع مجتمعنا الرائع!
تسجيلالمنشورات ذات الصلة | الردود | أدوات العرض | النشاط | |
---|---|---|---|---|
|
1
أبريل 24
|
1318 | ||
|
0
يناير 24
|
1051 | ||
|
1
سبتمبر 23
|
2290 | ||
|
2
أبريل 23
|
4315 | ||
get the model in js
تم الحل
|
|
3
مارس 25
|
2810 |