Hi Community,
I'am creating a widget (using Odoo 9c) which modified from Odoo 9c documentation (section: "Creating a New Type of Field"), and give name 'char2' widget. I put in use on my form with <field name="...." widget="char2"/> but it not working/no effect. The field type that I'm gonna use the widget with is Char.
On the form, I went developer mode and manage view, then look at the field properties, I can't find 'char2' (for that field) on the widget dropdown list.
Is anything I missed here? Any help will be very appreciated.
Below is the widget's JS
openerp.energy_survey = function(instance, local)
{
var QWeb = instance.web.qweb;
local.FieldChar2 = instance.web.form.AbstractField.extend(
{
init: function()
{
this._super.apply(this, arguments); this.set("value", ""); },
start: function()
{
this.on("change:effective_readonly", this, function()
{
this.display_field(); this.render_value(); }); this.display_field(); return this._super(); },
display_field: function()
{
var self = this; this.$el.html(QWeb.render("FieldChar2", {widget: this})); if (! this.get("effective_readonly"))
{
this.$("input").change(function()
{
self.internal_set_value(self.$("input").val()); }); }
},
render_value: function()
{
if (this.get("effective_readonly"))
{
this.$el.text(this.get("value")); } else {
this.$("input").val(this.get("value")); }
},
}); instance.web.form.widgets.add('char2', 'instance.energy_survey.FieldChar2'); }
here is __openerp__.py
'data': [
'energy_survey_view.xml',
'energy_survey_menu.xml',
],
'js': [
'static/src/js/energy_survey.js',
],
'demo': [
],
'qweb': [
'static/src/xml/*.xml',
],
'css': [
'static/src/css/energy_survey.css',
CSS
@charset "UTF-8";
.oe_field_char2
{
margin: 5px;
padding: 5px;
border-radius: 3px;
background-color: #F0EEEE;
}
here is the template XML
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="FieldChar2">
<div class="oe_field_char2">
<t t-if="! widget.get('effective_readonly')">
<input type="file" accept="image/*" capture="camera"></input>
</t>
</div>
</t>
</templates>