Skip to Content
Menu
This question has been flagged
5 Replies
11839 Rodiniai

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; });
Portretas
Atmesti

viewRegistry.add('form', FormAlertView);

if this does not work, try this :

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

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

Autorius

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

}

Autorius

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

   

Portretas
Atmesti
Related Posts Replies Rodiniai Veikla
3
rugs. 22
6976
1
rugp. 22
4538
3
kov. 21
1895
2
vas. 19
2685
0
vas. 19
3745