Skip to Content
Menu
This question has been flagged
5 Replies
11587 Zobrazenia

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; });
Avatar
Zrušiť

viewRegistry.add('form', FormAlertView);

if this does not work, try this :

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

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

Autor

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

}

Autor

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

Best Answer

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

   

Avatar
Zrušiť
Related Posts Replies Zobrazenia Aktivita
3
sep 22
6743
1
aug 22
4290
3
mar 21
1756
2
feb 19
2516
0
feb 19
3598