I'm loading flatpickr using this:
<script type="text/javascript">
jQuery(document).ready(function($){
$('#Mydatetime').flatpickr({
altInput: true,
altFormat: "M j, Y @ H:i",
enableTime: true,
dateFormat: 'Y-m-d\\TH:i'
});
});
<input type="text" id="Mydatetime" class="MyDate" name="my_expire_date" value="' . $variable . '"/>
The variable is just my datetime. It works, but I'd like to add a clear button similar to this. No matter what I do the button doesn't clear the date.
The example:
<a class="input-button" title="clear" data-clear>
<i class="icon-close"></i>
</a>
Seems straightforward, but I'm clearly missing something. Anyone got one of these close buttons working properly?
Use the following method:
const $flatpickr = $("#flatpickr_id").flatpickr();
$("#some_button_id").click(function() {
$flatpickr.clear();
})
$(function() {
$(".input_button").click(function() {
$('#Mydatetime')[0]._flatpickr.clear();
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With