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; });
viewRegistry.add('form', FormAlertView);
if this does not work, try this :
var core = require('web.core');
core.view_registry.add('form', FormAlertView);
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
}
Thanks for looking again, but still the exact same error message. It's not recognizing the displayAlertMessage function for some reason.