Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
2 Respostas
3843 Visualizações

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
Cancelar
Autor Melhor resposta

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
Cancelar
Melhor resposta

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
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
1
mai. 25
684
2
abr. 25
1213
0
jan. 25
733
1
dez. 24
1361
1
nov. 24
1655