Magento – adding calendar on form field in magento 2 not working error 404

calendardatepickermagento2

In frontend I've managed to add a form that loads in a modal shown after a product is added to cart. On that form a field must have a calendar on. I've used the attribute data-mage-init='{"calendar": {"showTime": false, "showOn":"both", "defaultDate":"-20y"}}' on the form field.
But on the console I see

"NetworkError: 404 Not Found –
http://testmagento2/pub/static/frontend/Magento/luma/en_US/calendar.js"
.

Indeed in that location there is no calendar.js. Instead I've found the calendar.js under http://testmagento2/pub/static/frontend/Magento/luma/en_US/mage/calendar.js

I can't figure out the problem.
Any help is appreciated! Thank you in advance!

Best Answer

ok... so the last idea I came up with was to include the following script inside .phtml file, and not use the data-mage-init attribute anymore:

<form action="" method="POST">
        <label for="name">Name: </label>
        <input type="text" id="name" name="name"/><br>
....
        <label for="birthdate">Birth date: </label>
        <input type="text" id="birthdate" name="birthdate"/><br>
</form>
    <script>
        require([
            "jquery",
            "mage/calendar"
        ], function($){

            $("#birthdate").calendar({
                showTime: false,
                //dateFormat: "yy-mm-dd"
            });
        });
    </script>