Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
3062 Vistas

Having problems loading a javascript function in Odoo 18.  Not sure how to access it.  It's loaded via the manifest into 'web.assets_frontend'.  In Odoo 17 it works fine.


Seems Odoo 18 encapsulates the function with some javascript?


The error I get is:

web.assets_frontend_lazy.min.js:3877 ReferenceError: removeURLParameter is not defined


Here is the code in assets_frontend_lazy.min.js:


/* /condition/static/src/js/remove_url_parameter.js */
odoo.define('@condition/js/remove_url_parameter', [], function(require) {
    'use strict';
    let __exports = {};
    function removeURLParameter(url, parameter) {
        var urlparts = url.split('?');
        if (urlparts.length >= 2) {
            var prefix = encodeURIComponent(parameter) + '=';
            var pars = urlparts[1].split(/[&;]/g);
            for (var i = pars.length; i-- > 0; ) {
                if (pars[i].lastIndexOf(prefix, 0) !== -1) {
                    pars.splice(i, 1);
                }
            }
            return urlparts[0] + (pars.length > 0 ? '?' + pars.join('&') : '');
        }
        return url;
    }
    return __exports;
});
;
Avatar
Descartar
Autor Mejor respuesta

This is the code that ended up working:

/** @odoo-module */
import publicWidget from "@web/legacy/js/public/public_widget";

publicWidget.registry.removeCondition = publicWidget.Widget.extend({
    selector: '.condition_sort_dropdown',
    events: {
        'click .condition_sort': '_removeCondition',
    },
        _removeCondition() {
            //prefer to use l.search if you have a location/link object
            var urlparts = location.href.split('?');
            if (urlparts.length >= 2) {

                var prefix = encodeURIComponent('condition') + '=';
                var pars = urlparts[1].split(/[&;]/g);

                //reverse iteration as may be destructive
                for (var i = pars.length; i-- > 0;) {
                    //idiom for string.startsWith
                    if (pars[i].lastIndexOf(prefix, 0) !== -1) {
                        pars.splice(i, 1);
                    }
                }

                location.href = urlparts[0] + (pars.length > 0 ? '?' + pars.join('&') : '');
            }
        }
});

export default publicWidget.registry.removeCondition;


Avatar
Descartar
Mejor respuesta

Hi,

I wanted to let you know that Odoo 18 now uses OWL (Odoo Web Library) for frontend development, replacing the old Backbone.js framework. OWL is a modern, component-based system, similar to React or Vue.js.

If you have any code based on Backbone.js, it will need to be updated to work with OWL.

Hope it helps

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
2
abr 25
500
0
ene 25
433
1
dic 24
927
1
nov 24
1176
1
oct 24
4955