[IMP] web: Allow displaying simple json fields

Purpose
=======

It is currently impossible to display a json field on a form view without
defining a specific widget.

Allow displaying the json field in its simplest form, aka the stringified
content in readonly mode.

TaskID: 3101400
This commit is contained in:
Yannick Tivisse
2023-07-05 14:21:28 +02:00
parent fda7ec5f1f
commit 5f93474570
2 changed files with 34 additions and 0 deletions
@@ -0,0 +1,26 @@
/** @odoo-module **/
import { _lt } from "@web/core/l10n/translation";
import { registry } from "@web/core/registry";
import { standardFieldProps } from "../standard_field_props";
import { Component } from "@odoo/owl";
export class JsonField extends Component {
static template = "web.JsonbField";
static props = {
...standardFieldProps,
};
get formattedValue() {
const value = this.props.record.data[this.props.name];
return value ? JSON.stringify(value) : "";
}
}
export const jsonField = {
component: JsonField,
displayName: _lt("Json"),
supportedTypes: ["jsonb"],
};
registry.category("fields").add("jsonb", jsonField);
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="web.JsonbField" owl="1">
<span t-esc="formattedValue" />
</t>
</templates>