Basic Form Handling with Owl.js + Odoo 17

26 November, 2025
VH CHAUDHARY

VH CHAUDHARY

Owl.js is a modern JavaScript framework that shines in creating dynamic web interfaces within Odoo applications. If you are working within the Odoo ecosystem, Owl.js is a powerful tool for handling user input through forms. Let's dive into the basics of how it works.


Key Concepts and Setup

  1. Owl Components: In Owl.js, you organize your web interfaces into reusable components. Each component is a self-contained unit with its own logic and rendering behavior. A form is a perfect example of a component.

  2. State: The concept of 'state' is central to Owl.js. The state represents the data within your component at a given moment in time. User input into your form fields directly modifies this state.

  3. Reactivity: Owl.js components are reactive. When the state changes, Owl.js seamlessly re-renders the relevant parts of your form to reflect the updates without manual DOM manipulation.


Building a Simple Form

Let's illustrate with a basic contact form example:


Explanation

  • Component Structure: We define a class ContactForm that extends the base owl.Component.
  • Initial State: Within the component, we initialize state with fields for name, email, and message.
  • Event Handlers: Functions like onNameChange, onEmailChange and onMessageChange are event handlers. Owl.js automatically binds them to input elements in your template. Whenever the user types in an input field, these functions update the corresponding state values.
  • Form Submission: The submitForm function would handle the logic involved in submitting the form data, potentially sending it to your Odoo backend.

Template Structure

Now, let's create a basic XML template to pair with this component:


  • t-on Directives: Notice the t-on-submit.prevent and t-on-input directives. These bind your form elements to the event handlers we defined in the JavaScript component.

Reference:

https://github.com/odoo/owl/blob/master/doc/reference/input_bindings.md

have an idea? lets talk

Share your details with us, and our team will get in touch within 24 hours to discuss your project and guide you through the next steps

happy clients50+
Projects Delivered20+
Client Satisfaction98%