Topic: DatePicker date-value wrong

gizmono free asked 4 years ago


Expected behavior data-value="2020,1,3" set to a Date like 2020,1,3 should show in the DatePicker as 3 Jan 2020.

Actual behavior It shows as 3 FEB 2020. Any Date you define it is one month more

Resources (screenshots, code snippets etc.) https://mdbootstrap.com/snippets/jquery/gizmono/1600858/


needledrag free commented 4 years ago

I had the same thing. The javascript array for months is 0 indexed so if you display the date in the date picker using the data-value the month should always be 1 less, alternatively you can just use the value tag to show the date as it comes though.

Hope this helps


gizmono free answered 4 years ago


needledrag, many thanks do understand now. And your proposed workaround works :-) @mdbootstrap: Will you fix this in further releases?


Grzegorz Bujański staff commented 4 years ago

I'm adding this to our to-do list.


gizmono free answered 4 years ago


Thanks for the hint. What exactly you mean with "just use the value tag"?


needledrag free commented 4 years ago

If you're using an html input for the date picker you can just put the date (already formatted) in the value attribute eg value="22/01/2020" but if you want to use the data-value attribute you will need to subtract 1 from the month value because months are a 0 based array, this is probably the best way forward tbh.



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: Free
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.11.0
  • Device: Web
  • Browser: Chrome, FireFox, Safari
  • OS: Apache, PHP
  • Provided sample code: No
  • Provided link: Yes