[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:
@@ -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>
|
||||
Reference in New Issue
Block a user