Skip to Content
Menu
This question has been flagged
2 Replies
3205 Views

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
Discard
Author 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
Discard
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
Discard
Related Posts Replies Views Activity
1
May 25
147
2
Apr 25
596
0
Jan 25
445
1
Dec 24
975
1
Nov 24
1229