Topic: Problem set date for datepicker
Claudio Baeza asked 3 years ago
Expected behavior I get date through AJAX with format yyyy/mm/dd (2021/05/05) , when I open the calendar I want see May 5, 2021 selected in the calendar
Actual behavior Always appear today date, if sent the form, hidden submit variable is empty.
Resources (screenshots, code snippets etc.) HTML
<div id="datepp" class="md-form md-outline input-with-post-icon datepicker">
<input placeholder="Select date" type="text" id="datep" name="datep" class="form-control">
<label for="example">Date</label>
<i class="fas fa-calendar input-prefix" tabindex=0></i>
</div>
JS
$('.datepicker').datepicker({format: 'yyyy/mm/dd', formatSubmit: 'yyyy/mm/dd', min: [2020,10,1], max: [2021,09,31]});
$("#datep").val("2021/05/05")
$("#datep").datepicker("update", new Date(2021,05,05));
2021/05/05 is get from web server through AJAX, I put the value as example
Marcin Luczak staff answered 3 years ago
Hi,
To set Datepicker value you can use set
method on the Datepicker instance. Please see my snippet:
https://mdbootstrap.com/snippets/jquery/marcin-luczak/3155467
Keep coding, Marcin
Claudio Baeza commented 3 years ago
Thanks you so much Marcin, it's worked fine.
Marcin Luczak staff commented 3 years ago
I'm happy that I could help :)
Keep coding, Marcin
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Resolved
- User: Free
- Premium support: No
- Technology: MDB jQuery
- MDB Version: MDB4 4.19.2
- Device: Desktop Computer
- Browser: Chrome
- OS: Windows 10
- Provided sample code: No
- Provided link: No