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.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- 客戶關係
- e-Commerce
- 會計
- 庫存
- PoS
- Project
- MRP
此問題已被標幟
Hello Khaled,
Here is the validation(regular expression) for the Email using JS(it is for email field in Website):
const re =
/^([a-z0-9][-a-z0-9_+.]*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,63}(?:\.[a-z]{2})?)$/i;
if (re.test(email) == false){
this.$('.email-valid').text("Please enter valid email address").show();
}
You can import re then customize above code in python.
Feel free to reach out us: lakhan@codespheretech.in
Hello Khaled! Here’s how you can add validation to the email field in the Contacts app using OWL:
First, inherit the Contact
form view in your custom module.
Next, create a new OWL component that extends the form view.
In your OWL component, use the @onWillStart
hook to access the form's record data and modify the email field's validation.
You can use JavaScript's built-in regular expressions or a library like validator.js
to validate the email format. Import the library in your JS file if needed.
Here's an example of how you might implement this:
@onWillStart
async willStart() {
await super.willStart();
this.model.load()
}
Finally, make sure your module is correctly loaded in Odoo and that your OWL component is properly registered to override the default form view.
For personalized assistance:
https://www.pragtech.co.in/contact-us-mql.html
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
1月 25
|
1416 | ||
|
0
9月 23
|
3349 | ||
|
2
8月 23
|
11518 | ||
|
0
8月 23
|
194 | ||
|
1
5月 23
|
2565 |