Topic: datepicker error console

Pellegrino priority asked 2 years ago


I have tried in every way to run an example of a datepicker on my pc. But in the console I have this error:if anyone can help me !!

html:

Dalla Data

javascript: const datepickerEl = document.getElementById('dalladata')const datepicker = new mdb.Datepicker(datepickerEl);datepicker.open();

console: manipulator.js:98 Uncaught TypeError: Cannot read properties of null (reading 'classList') at Object.addClass (manipulator.js:98:17) at vc._appendToggleButton (index.js:362:17) at vc._init (index.js:348:12) at new vc (index.js:212:10) at Function.getOrCreateInstance (index.js:1431:36) at HTMLDocument. (storicovisite.php:139:39) at j (jquery-1.11.0.min.js:2:27136) at Object.fireWith [as resolveWith] (jquery-1.11.0.min.js:2:27949) at Function.ready (jquery-1.11.0.min.js:2:29783) at HTMLDocument.K (jquery-1.11.0.min.js:2:30128)


Michał Duszak staff commented 2 years ago

Hello, could you please reproduce your issue in a snippet with MDB Snippets? Here is the link: https://mdbootstrap.com/snippets/ It will be easier to debug your issue, as we will be referencing the same environment.


Michał Duszak staff answered 2 years ago


If you load mdb.min.js file before the content, you can try to do init by yourself after the DOM content loads

For example:

const options = {
  format: 'dd-mm-yyyy'
}
const myDatepicker = new mdb.Datepicker(document.getElementById('myDatepicker'), options)

Fletcher Easton premium answered 2 years ago


I had the same issue. Current temporary fix is to import the datepicker specific JS files AFTER the DOM elements. See the code example below...

<div class="form-outline datepicker">
    <input type="text" class="form-control" id="mdb-date-picker">
    <label for="mdb-date-picker" class="form-label">Select a date</label>
</div>

<script type="text/javascript" src="/static/js/datepicker.min.js"></script>

Please note that in my project, the main mdb.min.js file(s) are linked BEFORE all of this content in the body.



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Priority
  • Premium support: Yes
  • Technology: MDB Standard
  • MDB Version: MDB5 3.10.2
  • Device: pc
  • Browser: chrome
  • OS: windows
  • Provided sample code: No
  • Provided link: No