Skip to Content
Menu
This question has been flagged
5 Replies
10620 Views

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
Discard

viewRegistry.add('form', FormAlertView);

if this does not work, try this :

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

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

Author

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

}

Author

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
Discard
Related Posts Replies Views Activity
3
Sep 22
5765
1
Aug 22
3491
3
Mar 21
1165
2
Feb 19
2113
0
Feb 19
3112