How to perform some action in javascript on clik of a formview button.
Say just to show alert in JS on click of a button.
Please show some code examples.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
How to perform some action in javascript on clik of a formview button.
Say just to show alert in JS on click of a button.
Please show some code examples.
Form View:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="assets_backend_accrediation" name="web_submit_ajax" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/your_module_name/static/src/js/your_js_file_name.js"/>
</xpath>
</template>
<record model="ir.ui.view" id="view_my_model_form">
<field name="name">my.model.name.form</field>
<field name="model"> my.model.name </field>
<field name="arch" type="xml">
<form string="Expense Type">
<sheet>
<group>
<widget name="my_widget"/>
</group>
</sheet>
</form>
</field>
</record>
</data>
</odoo>
JavaScript
odoo.define('my_module.my_widget', function (require)
{
var Widget= require('web.Widget');
var widgetRegistry = require('web.widget_registry');
var FieldManagerMixin = require('web.FieldManagerMixin');
var MyWidget = Widget.extend(FieldManagerMixin, {
init: function (parent, model, context)
{
this._super(parent);
FieldManagerMixin.init.call(this);
this._super.apply(this, arguments);
},
start: function() {
var self = this;
this._super.apply(this, arguments);
var html ='<button id="btn_submit" class="btn btn-primary">Add Previous Compliance</button>';
this.$el.html(html);
this.$('#btn_submit').click(function(ev){
ev.preventDefault();
ev.stopPropagation();
alert("Submit button clicked");
});
},
});
widgetRegistry.add( 'my_widget', MyWidget );
});
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
1
Jun 15
|
9721 | ||
|
5
Dec 17
|
4745 | ||
|
1
Apr 16
|
4194 | ||
|
2
Apr 16
|
2912 | ||
|
1
Aug 23
|
894 |