Skip to Content
Menu
This question has been flagged
2 Replies
3064 Zobrazenia

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
Zrušiť
Autor Best Answer

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
Zrušiť
Best Answer

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
Zrušiť
Related Posts Replies Zobrazenia Aktivita
2
apr 25
505
0
jan 25
433
1
dec 24
928
1
nov 24
1177
1
okt 24
4962