Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • Apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

How to add an existing field validation with OWL?

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
javascriptodooOWL
2 Besvarelser
980 Visninger
Avatar
Khaled

I want to add validation for the email field in the Contacts app, however, I don't know what libraries should I import in my JS file. Also, how to edit the field validation using OWL.

0
Avatar
Kassér
Avatar
Marvin Accuweb.Cloud
Bedste svar


Hello Khaled,

Here’s an example of how you can add a simple validation for the email field in the Contacts app using OWL. You don’t need any extra libraries; OWL and the web client utilities are already available in Odoo.


/** @odoo-module **/

import { CharField } from "@web/views/fields/char/char_field";

import { patch } from "@web/core/utils/patch";

patch(CharField.prototype, "email_validation_patch", {

    async onInput(ev) {

        await super.onInput(ev);

        if (this.props.name === "email") {

            const value = ev.target.value || "";

            const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

            const isValid = emailPattern.test(value);

            if (!isValid && value) {

                this.notification.add("Please enter a valid email address.", { type: "warning" });

                ev.target.classList.add("o_invalid_field");

            } else {

                ev.target.classList.remove("o_invalid_field");

            }

        }

    },

});


Add this file under your custom module path:

/static/src/js/email_validation.js

Then include it in your manifest file:

'assets': {

    'web.assets_backend': [

        '/your_module/static/src/js/email_validation.js',

    ],

},


After updating and reloading, the email field will show a warning message when the format is invalid.



0
Avatar
Kassér
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Bedste svar

Hi,


The error occurs because your pos_data_loader.js is importing @point_of_sale/app/store/pos_global_state, which exists only in Odoo 19, not Odoo 18. In Odoo 18, the equivalent is point_of_sale.models or PosModel, and your code should patch its prototype instead. Additionally, your custom JS must be included in the point_of_sale.assets bundle in your module manifest. Using Odoo 19 import paths in Odoo 18 causes unmet dependency errors, so adapting the imports and ensuring proper asset inclusion will resolve the issue.


Try the following code,


/** @odoo-module **/

import { patch } from "web.utils";

import PosModel from "point_of_sale.models";  // <-- Correct path for v18


console.log("PSMS: Extending POS data models for Odoo 18");


patch(PosModel.prototype, "psms_pos_data_loader", {

    async _load_data() {

        console.log("PSMS: _load_data running...");


        await super._load_data();


        const orm = this.env.services.orm;

        if (!orm) return;


        const configs = await orm.searchRead("pos.config", [], [

            "id", "name", "display_stock", "nozzle_ids", "pump_ids", "tanks_ids"

        ]);


        const currentConfigId = this.config_id;

        const currentConfig = configs.find(c => c.id === currentConfigId);


        if (!currentConfig) return;


        this.display_stock = currentConfig.display_stock;

        this.nozzle_ids = currentConfig.nozzle_ids || [];

        this.pump_ids = currentConfig.pump_ids || [];

        this.tanks_ids = currentConfig.tanks_ids || [];


        console.log(" POS CONFIG", this);


        // Load nozzle data if any

        if (this.nozzle_ids.length) {

            const nozzles = await orm.searchRead("petrol.nozzle", [["id", "in", this.nozzle_ids]], [

                "id", "name", "pump_id", "tank_id", "product_id"

            ]);

            this.db.nozzle_by_id = {};

            for (const nozzle of nozzles) this.db.nozzle_by_id[nozzle.id] = nozzle;

            console.log(` PSMS: Loaded ${nozzles.length} nozzles for this POS`);

        }

    }

});


Hope it helps

0
Avatar
Kassér
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Tilmeld dig
Related Posts Besvarelser Visninger Aktivitet
py.eval in Javascript
javascript OWL
Avatar
0
jan. 25
1828
Uncaught Javascript Error > Invalid handler (expected a function, received: 'undefined")
javascript OWL
Avatar
0
sep. 23
3788
Odoo 16 : How to use message_post() to send message in the chatter? Løst
odoo OWL
Avatar
Avatar
Avatar
2
aug. 23
12651
Save and get the value of variable from backend
javascript odoo
Avatar
0
aug. 23
194
is there onload hook in v13 JS FormViewDialog ? Løst
javascript OWL
Avatar
Avatar
1
maj 23
2922
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now