How to Modify JS Dialog Box in Odoo 16 (2024)

How to Modify JS Dialog Box in Odoo 16 (1)

By: Aiswarya JP

JUN 6,2024

Functional Technical

In Odoo, JS dialog boxes or popups are very helpful in showing messages, confirming actions, alerts, warnings, etc.

By default in Odoo, the Dialog Boxes have default properties and styles.

But it’s also possible to modify the properties and style of the Dialog boxes to fit our business needs.

In this blog, we will explore how to modify the JS Dialog boxes in Odoo 16, which will help to enhance the appearance, behavior, and functionalities of Dialog boxes.

Dialog.confirm(self, "Are you sure you want to change the stage?", {
title: _t("Confirmation"),
confirm_callback: function(){
console.log("Click Confirm");
},
cancel_callback: function(){
console.log("Click Cancel");
}
});

Above shown is a simple Confirmation Dialog. Let’s see how we can modify this Dialog using different predefined parameters in JS.

1). title :

The “title” parameter can be used to specify the title or heading of the message

Dialog.confirm(self, "Are you sure you want to change the stage?", {
title: _t("Confirmation"),
confirm_callback: function(){
console.log("Click Confirm");
},
cancel_callback: function(){
console.log("Click Cancel");
}
});
How to Modify JS Dialog Box in Odoo 16 (2)

2. size :

The “size” parameter can be used to adjust the width of the Dialog box. Four options are available for this parameter and they are 'extra-large', 'large', 'medium', and 'small'.

Below is an example of a size set as 'extra-large', likewise we can set any of the four options as per our desire

Dialog.confirm(self, "Are you sure you want to change the stage?", {
title: _t("Confirmation"),
size: ‘extra-large’,
confirm_callback: function(){
console.log("Click Confirm");
},
cancel_callback: function(){
console.log("Click Cancel");
}
});

How to Modify JS Dialog Box in Odoo 16 (3)

3. fullscreen :

Fullscreen is used to determine whether or not the dialog should be open in fullscreen mode. Its main use case is mobile.

Dialog.confirm(self, "Are you sure you want to change the stage?", {
title: _t("Confirmation"),
fullscreen: true,
confirm_callback: function(){
console.log("Click Confirm");
},
cancel_callback: function(){
console.log("Click Cancel");
}
});

How to Modify JS Dialog Box in Odoo 16 (4)

4. dialogClass :

In the dialogClass parameter, we can specify the class that needs to be added to the body of the Dialog box.

.dialog-body{
background-color: #ccf9ff;
}
Dialog.confirm(self, "Are you sure you want to change the stage?", {
title: _t("Confirmation"),
dialogClass: 'dialog-body',
confirm_callback: function(){
console.log("Click Confirm");
},
cancel_callback: function(){
console.log("Click Cancel");
}
});

How to Modify JS Dialog Box in Odoo 16 (5)

5. $content :

$content is a jQuery parameter. It will replace the modal body.

Dialog.confirm(self, "Are you sure you want to change the stage?", {
title: _t("Confirmation"),
$content: $('<div>', {
text: _t("Need to change the stage?")
}),
confirm_callback: function(){
console.log("Click Confirm");
},
cancel_callback: function(){
console.log("Click Cancel");
}
});

How to Modify JS Dialog Box in Odoo 16 (6)

6. buttons:

buttons is a list parameter that will include a list of button descriptions. If the “buttons” parameter is not specified, then an "OK" primary button will added to allow closing the dialog.

The options that can be used inside the buttons parameter are listed below.

a) text - the label of the button.

b) classes - specify the class to be added to the buttons. If there is only one button, classes will default to the 'btn-primary' otherwise 'btn-secondary'.

c) close - decides whether to close the dialog box after clicking the button.

d) click - define the function that is to be called when clicking the button.

e) disabled - if set as true then that button will be disabled and will not be clickable.

Dialog.confirm(self, "Are you sure you want to change the stage?", {
title: _t("Confirmation"),
buttons: [
{
text: _t("Confirm"),
classes: 'btn-primary',
close: true,
click: function () {
console.log("Confirm button clicked")
},
},
{
text: _t('Cancel'),
close: true,
disabled: true,
click: function () {
console.log("Cancel button clicked")
},
}
]
});

How to Modify JS Dialog Box in Odoo 16 (7)

7)technical :

If set to false, the Dialog box will have the standard frontend style.

Dialog.confirm(self, "Are you sure you want to change the stage?", {
title: _t("Confirmation"),
technical: false,
confirm_callback: function(){
console.log("Click Confirm");
},
cancel_callback: function(){
console.log("Click Cancel");
}
});

8) $parentNode :

$parentNode is a jQueryElement parameter. This will determine the element in which the dialog box will be appended, by default it will be in the body.

Dialog.confirm(self, "Are you sure you want to change the stage?", {
title: _t("Confirmation"),
$parentNode: $(document.body.querySelector(".o_dialog_container")),
confirm_callback: function(){
console.log("Click Confirm");
},
cancel_callback: function(){
console.log("Click Cancel");
}
});

9) backdrop :

Determines the kind of modal backdrop to use. It will take true/false and string values.

Dialog.confirm(self, "Are you sure you want to change the stage?", {
title: _t("Confirmation"),
backdrop: 'static',
confirm_callback: function(){
console.log("Click Confirm");
},
cancel_callback: function(){
console.log("Click Cancel");
}
});

If “backdrop” is set as “true”, then we can click outside of this Dialog to close it. If it is “static” or “false”, cannot click outside to close it.

10) renderHeader :

Decide the visibility of the header in the Dialog box. If it is set as true, then the Header section will show in the Dialog, otherwise, it will not rendered.

Dialog.confirm(self, "Are you sure you want to change the stage?", {
title: _t("Confirmation"),
renderHeader: false,
confirm_callback: function(){
console.log("Click Confirm");
},
cancel_callback: function(){
console.log("Click Cancel");
}
});

How to Modify JS Dialog Box in Odoo 16 (8)

11)renderFooter :

Decide the visibility of the footer in the Dialog box. If it is set as true, then the Footer section will show in the Dialog, otherwise, it will not rendered.

Dialog.confirm(self, "Are you sure you want to change the stage?", {
title: _t("Confirmation"),
renderFooter: false,
confirm_callback: function(){
console.log("Click Confirm");
},
cancel_callback: function(){
console.log("Click Cancel");
}
});

How to Modify JS Dialog Box in Odoo 16 (9)

12)onForceClose :

Here we can define the Callback function that triggers when the Dialog is closed by other means (e.g. pressing ESC ) than with the buttons.

Dialog.confirm(self, "Are you sure you want to change the stage?", {
title: _t("Confirmation"),
onForceClose: function() {

}
confirm_callback: function(){
console.log("Click Confirm");
},
cancel_callback: function(){
console.log("Click Cancel");
}
});

By using the above-mentioned parameters, we can modify the JS Dialog boxes in Odoo16. Refer to our previous blog aboutHow to Use the Odoo JS Dialog/Popup to read more about the JS Dialog Box in Odoo.


How to Modify JS Dialog Box in Odoo 16 (2024)

FAQs

How to add js in Odoo 16? ›

Let's check how we may do this.
  1. Here is the module structure for adding a custom Javascript file to POS,
  2. During the start of the POS session, define the console. odoo. define('custom_pos. pos', function (require) { "use strict"; console. ...
  3. JavaScript asset registration at the point of sale:

How do you open a dialog box in JavaScript? ›

JavaScript should be used to display the <dialog> element. Use the .showModal() method to display a modal dialog and the .show() method to display a non-modal dialog. The dialog box can be closed using the .close() method or using the dialog method when submitting a <form> that is nested within the <dialog> element.

How to define js file in Odoo? ›

Hi, You can add your javascript file under module_name -> static -> src-> js folder.

How do you add a JavaScript script? ›

Adding JavaScript into an HTML Document

You can add JavaScript code in an HTML document by employing the dedicated HTML tag <script> that wraps around JavaScript code. The <script> tag can be placed in the <head> section of your HTML or in the <body> section, depending on when you want the JavaScript to load.

How to import a js script? ›

To include an external JavaScript file, we can use the script tag with the attribute src . You've already used the src attribute when using images. The value for the src attribute should be the path to your JavaScript file. This script tag should be included between the <head> tags in your HTML document.

What are the options of JavaScript dialog box? ›

JavaScript has three kind of popup boxes: Alert box, Confirm box, and Prompt box.

How to create a dialog box? ›

To create a new dialog box

In Resource View, right-click your . rc file and select Add Resource. In the Add Resource dialog box, select Dialog in the Resource Type list, then choose New. If a plus sign (+) appears next to the Dialog resource type, it means that dialog box templates are available.

What is the command to open the dialogue box? ›

The Run dialogue box in Microsoft Windows provides a quick and convenient way for you to launch programmes, open websites, and access several Windows settings. Let's find out how it works. The quickest way to access the Run command window is to use the keyboard shortcut Windows + R.

How to call js function in Python Odoo? ›

If you need to call a Python function from JavaScript in Odoo 15, you can use the Odoo's RPC (Remote Procedure Call) mechanism to call the Python function on the server and get the result back to the browser. You can use the odoo. jsonRpc() method provided by the Odoo JavaScript API to call a Python method.

How to add CSS file in Odoo 16? ›

Creating CSS /JavaScript Files in Odoo
  1. Create a new folder called 'static' under Odoo's recommendations.
  2. Open this folder and make a new folder called 'src. '
  3. After creating the 'src' folder, make a new one called 'CSS,' 'js,' or 'images,' based on the file you need to include.
  4. Create a CSS file.
Mar 14, 2022

How to show data in js? ›

JavaScript can "display" data in different ways:
  1. Writing into an HTML element, using innerHTML .
  2. Writing into the HTML output using document.write() .
  3. Writing into an alert box, using window.alert() .
  4. Writing into the browser console, using console.log() .

How do I add a menu in Odoo 16? ›

If you have enabled the debug mode in Odoo, you can access these features. Suppose, for instance, we need to create the new menu item within “Inventory > Product.” In that case, you can navigate to “Settings > Technical > Menu Items,” search for 'product,' and select 'Inventory / Product.

How to add using js? ›

Add Two Numbers in JavaScript Using + Operator

var sum = number1 + number2;: This line creates another variable called sum. The + operator is used to add the values of number1 and number2. The result of this addition (5 + 3) is stored in the sum variable.

How to add JavaScript libraries? ›

Press Ctrl+Alt+S to open the IDE settings and select Languages & Frameworks | JavaScript | Libraries. On the Libraries page, click Add.

How to add js to form? ›

Using JavaScript in HTML forms
  1. <form> declares a new form: name="myForm" names the form. ...
  2. <input> starts an input element: type="text" defines the type of input. ...
  3. <input type="button"> defines a button object. ...
  4. The testResults() function is defined in our JavaScript.
Jan 12, 2023

Top Articles
Latest Posts
Article information

Author: Wyatt Volkman LLD

Last Updated:

Views: 5702

Rating: 4.6 / 5 (46 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Wyatt Volkman LLD

Birthday: 1992-02-16

Address: Suite 851 78549 Lubowitz Well, Wardside, TX 98080-8615

Phone: +67618977178100

Job: Manufacturing Director

Hobby: Running, Mountaineering, Inline skating, Writing, Baton twirling, Computer programming, Stone skipping

Introduction: My name is Wyatt Volkman LLD, I am a handsome, rich, comfortable, lively, zealous, graceful, gifted person who loves writing and wants to share my knowledge and understanding with you.