Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
5 Trả lời
11963 Lượt xem

I'm displaying a Bootstrap alert that automatically fades after some time, by creating a JS module that extends FormView and using the js_class attribute in my view. I've found that when I use FormRenderer.include({...}), the code works as expected, but when I use FormRenderer.extend({...}), the error self.renderer.displayMessageAlert is not a function is raised. I'd prefer to extend over include, so if anyone knows how to make the code work with extend, I'd appreciate it. My code is:

odoo.define('my_module.FormAlertView', function (require) {
  "use strict";

  var FormView = require('web.FormView');
  var FormController = require('web.FormController');
  var FormRenderer = require('web.FormRenderer');

  var viewRegistry = require('web.view_registry');

  var FormAlertController = FormController.extend({
    saveRecord: function () {
      var self = this;
      return this._super.apply(this, arguments).then(function () {
        self.renderer.displayMessageAlert();
      })
    },

  });

  var FormAlertRenderer = FormRenderer.extend({
    displayMessageAlert: function () {
      this.$('.o_alert_fade').addClass('in');
      window.setTimeout(function () {
        $('.o_alert_fade').removeClass('in');
      }, 2000);
    },
  });

  var FormAlertView = FormView.extend({
    config: _.extend({}, FormView.prototype.config, {
      Renderer: FormAlertRenderer,
      Controller: FormAlertController,
    })
  });
viewRegistry.add('form_alert_view', FormAlertView);
return FormAlertView; });
Ảnh đại diện
Huỷ bỏ

viewRegistry.add('form', FormAlertView);

if this does not work, try this :

var core = require('web.core');

core.view_registry.add('form', FormAlertView);

Tác giả

Hi @Ibrahim, unfortunately neither solution resolved my issue.

I think since you added an extend, you need to consider them all in your viewregistry, not ony the last one. Like this :

viewRegistry.add('FormView', FormAlertView);

viewRegistry.add('FormController', FormAlertController);

viewRegistry.add('FormRenderer', FormAlertRenderer);

return {

FormAlertView: FormAlertView,

FormAlertController: FormAlertController,

FormAlertRenderer: FormAlertRenderer

}

Tác giả

Thanks for looking again, but still the exact same error message. It's not recognizing the displayAlertMessage function for some reason.

Câu trả lời hay nhất

Hello zach,

Here you need to return "FormRenderer" & "FormController" variable at the end instead of the "FormAlertView" variable


viewRegistry.add('form_alert_view', FormAlertView);


return {

    Renderer: BaseSettingRenderer,

    Controller: BaseSettingController,

};

Regards,




Email:   odoo@aktivsoftware.com

Skype: kalpeshmaheshwari

   

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 9 22
7142
1
thg 8 22
4688
3
thg 3 21
1977
2
thg 2 19
2778
0
thg 2 19
3830