Widgets are very useful tools available in the Odoo web library to perform certain tasks such as easy visualisation of data for better understanding by the user. There are many field widgets available in Odoo by default. Some examples are the boolean toggle for boolean fields, the date picker for date fields, and many2many_tags for many2many fields.
Let us create a custom colour picker widget that stores a colour value in an integer field.
First, we will create the integer field for storing the colour value.
Now add this field in the view of contacts form.
This would look as shown below in the Odoo contacts form.
A normal integer field with label Colour Index.
Since we have created the template of the widget, let’s give the style to the widget with the style sheet.
Since the definitions of our field widget are now completed, let’s now add it to our field.
Upon upgrading the module we can see that our integer colour field would have changed as shown below.
And here we can select one colour and the corresponding value will store in the integer field.
Using this method we can create our own custom widgets and add them to the Odoo web library and use them whenever required.
Widgets can simplify a user’s task by creating user-friendly widgets. That looks simple and easy to use, thus simplifying a task that might not be as easy as it seems when using a widget. We can reuse more useful widgets as required since widgets that are pleasing to users always appreciate the eyes and are easily understandable and usable.