Todo List App - OWL Javascript Framework Tutorial
  • /
  • Odoo OWL/
  • Todo List App - OWL Javascript Framework Tutorial

In this tutorial, we will be creating a simple Todo List App using Odoo OWL Framework. We will start creating from plain html, css and javascript. Using the basic functionalities, you will understand on how to implement OWL Framework easily.

Below are the needed files and application for this tutorial:

Setup the Development Environment

First thing that we need to do is to setup our development environment. Since we need only a static server, we can just simply create a new folder to any location we want and let's name it as todo app. Using Visual Studio Code editor, let's import this folder and create the following basic files:

  • index.html - used to display user interfaces to be displayed on the web browser
  • styles.css - used to add custom styles since we will be using Bootstrap CSS.
  • app.js - used for dynamic content and to make the web page interactive

In our index.html file, copy the code below and import styles.css and app.js.

Install Live Server Extension

For easier development, we need to install Live Server VS Code Extension for hot reload. To install, go to Extensions and search Live Server or click this link Open https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer. Click install and wait until done.

vs code live server extension

Once installed, go back to index.html and at the bottom right corner, you will see Go Live. Click it and you will be directed automatically to the browser.

vs code live server go live

Install Bootstrap CSS/Icons and OWL Framework

Since this tutorial is not about CSS, we will be using Open bootstrap cssbootstrap css and Open bootstrap iconsbootstrap icons so that we can focus more on Odoo OWL Framework. To download OWL javascript file, go to their github link latest release Open https://github.com/odoo/owl/releases/latesthttps://github.com/odoo/owl/releases/latest and under assets, choose Open owl.iife.jsowl.iife.js or Open owl.iife.min.jsowl.iife.min.js since these files are built to run directly on the browser and not by bundled by other tools.

In the same index.html, copy the code below:

Build the User Interface

Before using OWL Framework, let's build first the user interface so that styling and designing will be done on this stage and later we can focus only on javascript files using OWL. Using bootstrap classes, components and icons, copy the code below.

Create new OWL component

Now that the user interface is done, we can start using OWL Framework. To verify if owl is working, let's open app.js console log owl using the code below:

You should see a console log similar to the image below.

console log owl

There are three basic class and functions in owl to start our new component which we will import as follows:

  • Component - used to create new Component
  • xml - used to design the user interface or the template which will show in the web browser
  • mount - used to apply the xml template being defined and select which part on the page it will be mounted.

Copy the code below to and save it to app.js file.

Be sure to add any div in index.html with id as root since that is what being selected in mount method. Let's try it between the title description and task form.

Save it and noticed that "Test OWL" has been added in the browser.

test owl new component

Now that we know it is working fine, we can remove task form and task list in index.html and move it in app.js.

Add static list of task

For now let us statically add our list of task. In adding a list of task, first, we need to import useState from owl. To initialize the state, we need to add it under setup life cycle. In the template, we will use QWEB "foreach" directive to iterate to each task. In addition, we will use t-key to each task to avoid error. This is the same like mapping list in reactjs.

Now that our static list is working, we can now access each task and add the name and color.

Create dynamic task

Let's make our task dynamic which will allow us to add task name and task color using the form we added. In order to make this happen, we need to create a new state that will hold our task. We will be using t-model and t-value to bind our state to the form inputs.

Create new subcomponent for each task

It is good to separate our components into subcomponent so that we can manage it easier, hence, will make it modular. We will separate each task as subcomponent and then pass the states from parent component and access it using props.

Add toggle task functionality

Let's add toggle functionality which add line through to the our task name which means the task has been completed. We will use isCompleted state to add the style to task checkbox label.

Add delete task functionality

To add delete functionality, we need to use bind since the delete function start from our Task subcomponent and will be passed to the parent component which is Root. Under parent component, we will get the index of the task and remove it to tasks state.

Add edit task functionality

Lastly, let's add edit functionality. Unlike toggle and delete functionality, we need to add a new state in our task component since we need to bind it to the form input for us to get the new task name.

Let's add new form input and new state isEditing for us to show and hide this form input. We then use same functionality in deleting task.

Congratulation! You're now able to create a Todo list app using OWL Framework. Please leave comments below if you have issues. You can also watch video version of this tutorial below.

Todo List App - OWL Javascript Framework Tutorial