Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Odoo9c: Creating widget not recognize (can't be used by widget="char2")

By
Prihadi Ramadhany
on 10/17/16, 9:58 AM 120 views

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>

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 10/17/16, 9:58 AM
Seen: 120 times
Last updated: 10/17/16, 10:36 AM