← Back to team overview

openerp-india team mailing list archive

[Bug 1301474] Re: [trunk/7.0] Widget t-foreach - No enumerator given to foreach

 

Ok I finally found the problem, so not this is not a bug and I'll answer
to the tickets in help.openerp.com.

As I found by looking at some code in web client, you need to initialize
the variable in init, like this :

    init: function (field_manager, node) {
        this._super(field_manager, node);
        this.votes = [];
    },


    start: function() {
        this._super();
        this.votes = ["test", "test"]; //this.get('value');
    },

No more problem after that. I close the ticket.

** Changed in: openobject-addons
       Status: New => Invalid

-- 
You received this bug notification because you are a member of OpenERP
Indian Team, which is subscribed to OpenERP Addons.
https://bugs.launchpad.net/bugs/1301474

Title:
  [trunk/7.0] Widget t-foreach - No enumerator given to foreach

Status in OpenERP Addons (modules):
  Invalid

Bug description:
  Hi everyone,

  I suspect we have a bug with the widget system. I can't make it work
  with the t-foreach in qweb, when I try I have the following error

  Error: QWeb2 - template['VoteFiveStar']: Runtime Error: Error: QWeb2 -
  template['VoteFiveStar']: No enumerator given to foreach

  Here is my javascript file :

  openerp.web_widget_vote = function(instance) {

  instance.web.form.VoteFiveStar = instance.web.form.FieldChar.extend({
      template: 'VoteFiveStar',

      start: function() {
          this._super();
          this.votes = ["test", "test"];    //this.get('value');
      },

  });

  instance.web.form.widgets = instance.web.form.widgets.extend({
      'vote_five_star' : 'instance.web.form.VoteFiveStar',
  });

  };

  
  And my template file :

  <?xml version="1.0" encoding="UTF-8"?>
  <templates id="template" xml:space="preserve">
  <t t-name="VoteFiveStar">
          <t t-foreach="widget.votes" t-as="vote">
  <p><t t-esc="vote"/></p>
          </t>

      <span class="oe_form_field oe_form_field_vote_five_star">
          <a t-att-name="widget.name" string="-2" class="oe_e star_vote_five_star oe_star_off">7</a>
          <a t-att-name="widget.name" string="-1" class="oe_e star_vote_five_star oe_star_off">7</a>
          <a t-att-name="widget.name" string="0" class="oe_e star_vote_five_star oe_star_off">7</a>
          <a t-att-name="widget.name" string="1" class="oe_e star_vote_five_star oe_star_off">7</a>
          <a t-att-name="widget.name" string="2" class="oe_e star_vote_five_star oe_star_off">7</a>
          <a t-att-name="widget.name" class="oe_e ok_vote_five_star" style="display:none;">8</a>
      </span>
  </t>
  </templates>

  If I replace the foreach by a 
  <p><t t-esc="widget.votes"/></p>
  I have no more the error message and I have a "test,test" displayed, so the variable is clearly passed to the template.

  
  I don't understand what is happening... And it's seems I'm not the only one :
  http://help.openerp.com/question/40055/web-module-qwebrender-error-no-enumerator-given-to-foreach/
  http://help.openerp.com/question/21396/qweb-cant-use-t-foreach/
  http://help.openerp.com/question/5823/qweb-to-display-record-in-web-module/

  No answers on all theses tickets until now, there is definitely
  something which is wrong.

  If you want to check my branch : 
  https://code.launchpad.net/~yannick-buron/wezer/openerp-wezer
  The files :
  http://bazaar.launchpad.net/~yannick-buron/wezer/openerp-wezer/view/head:/web_widget_vote/static/src/js/vote.js
  http://bazaar.launchpad.net/~yannick-buron/wezer/openerp-wezer/view/head:/web_widget_vote/static/src/xml/vote.xml

  Thanks a lot for your help.

To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-addons/+bug/1301474/+subscriptions


References