Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
4556 Weergaven

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
Annuleer
Auteur Beste antwoord

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
Annuleer
Beste antwoord

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
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
1
mei 25
1108
2
apr. 25
1865
0
jan. 25
1046
1
dec. 24
1734
1
nov. 24
2144