Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

valentin_vranic's avatar

Assets not loaded

For some reason the assets won't load. I have a popup modal, where after closing div tag I'm trying to include flatpickr as follows. I have another popup modal where I'm using select2 (even if Caleb is not recommending it), but it's working as its needed to. And I'm including the same as I'm trying with flatpickr

@assets
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/flatpickr.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/flatpickr.min.css">
@endassets

@script
Flatpickr init....
@endscript
0 likes
1 reply
LaryAI's avatar
Level 58

It seems like you're trying to include Flatpickr assets and initialize it within a modal. If the assets are not loading, there could be several reasons for this. Here's a step-by-step solution to troubleshoot and resolve the issue:

  1. Check the Network Tab: Open your browser's developer tools and check the Network tab to see if the Flatpickr assets are being requested and loaded without any errors.

  2. Correct Asset Directives: Ensure that you are using the correct directives to include assets in your framework. If you are using Laravel, for example, you should use the asset helper function or mix if you are using Laravel Mix.

  3. Asset Loading Order: Make sure that the Flatpickr script is loaded after jQuery if it's being used, as some plugins depend on jQuery being available before they initialize.

  4. DOM Ready: Ensure that you are initializing Flatpickr after the DOM is fully loaded. This can be done by placing your initialization script at the bottom of the body or using a DOM ready function.

  5. Modal Event: If you are initializing Flatpickr inside a modal, make sure that the initialization code runs after the modal is shown, as the input field needs to be present in the DOM for Flatpickr to attach to it.

Here's an example of how you might include and initialize Flatpickr correctly:

<!-- Include Flatpickr CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/flatpickr.min.css">

<!-- Include Flatpickr JS -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/flatpickr.min.js"></script>

<!-- Your modal HTML here -->

<!-- Initialize Flatpickr -->
<script>
document.addEventListener('DOMContentLoaded', function() {
    // Assuming you have a modal toggle event or a callback when the modal is shown
    yourModalOnShownCallbackFunction = function() {
        // Initialize Flatpickr on your input field
        flatpickr(".your-input-selector", {
            // Flatpickr options here
        });
    };
});
</script>

Replace yourModalOnShownCallbackFunction with the actual function or event that triggers when your modal is shown. Also, replace .your-input-selector with the actual selector for your input field.

If you are using a JavaScript framework or library that has its own way of handling DOM content (like Vue, React, etc.), make sure to initialize Flatpickr within the lifecycle methods or hooks provided by those frameworks.

If you've checked all these points and the assets are still not loading, please provide more context or code snippets, so we can help you further troubleshoot the issue.

Please or to participate in this conversation.