Assets in formwidgets are not loaded

I’m migrating plugins to OC 3.1.
One of the plugins uses a formwidget which loads the intlTelInput javascript library. The assets are loaded using the loadAssets() function.

    protected function loadAssets()
    {
        $this->addCss('css/intlTelInput.min.css', 'core');
        $this->addJs('js/intlTelInput.min.js', 'core');
        $this->addJs('js/init.js', 'core');
    }

Because there’s no page refresh when loading forms and lists in version 3.1 the assets are not loaded. I need to refresh the page manually to load these files.
Is there a solution or work arround for this?

Hi and welcome @Densit,

Something doesn’t add up here. If the includes are available on refresh, they should be loaded for any visit.

It is possible that even though the scripts are loaded, the events are not firing as expected since the Turbo Router uses a slightly different page lifecycle. For example, controls should be initialized with the page:loaded event:

addEventListener('page:loaded', function() {
    // Page has rendered something new
});

More can be found in the documentation: Turbo Router - October CMS - 3.x

Alternatively, you can disable the turbo router by adding this to your backend controller:

/**
 * @var bool turboVisitControl forces a reload
 */
public $turboVisitControl = 'disable';

However, since it is a form widget, you may need to disable it globally.

// config/backend.php
//
'turbo_router' => false,

It may be easier to update the code to use the latest AJAX events instead.

Hi @daft

Thanks for the support and advice.
I updated the javascript code and now it’s working with Turbo Router

1 Like