Bootstrap - datetimepicker add custom button like Today
For now i found this solution:
$('#route-from-date').datetimepicker({
autoclose: true,
language: 'pl'
});
$('#route-to-date').datetimepicker({
autoclose: true,
language: 'pl',
//todayBtn: 'ok'
});
$('.datetimepicker tfoot').append('<tr><th colspan="7" class="today_">Dzisiaj</th></tr><tr><th colspan="7" class="yesterday">Wczoraj</th></tr><tr><th colspan="7" class=" week">Tydzień</th></tr>');
$('.datetimepicker tfoot th').on('click',function(){
var $th = $(this);
var d = new Date();
var fd,td;
if($th.hasClass('yesterday')){
d.setDate(d.getDate() - 1);
}
else if ($th.hasClass('week')){
d.setDate(d.getDate() - 7);
fd = d.getFullYear() + '-' + ((d.getMonth()<10)? '0'+(d.getMonth()+1) : d.getMonth()+1 ) + '-' + ((d.getDate()<10)? '0'+d.getDate() : d.getDate() ) + ' 00:00';
d.setDate(d.getDate() + 7);
td = d.getFullYear() + '-' + ((d.getMonth()<10)? '0'+(d.getMonth()+1) : d.getMonth()+1 ) + '-' + ((d.getDate()<10)? '0'+d.getDate() : d.getDate() ) + ' 23:59';
}
if(!$th.hasClass("week")){
fd = d.getFullYear() + '-' + ((d.getMonth()<10)? '0'+(d.getMonth()+1) : d.getMonth()+1 ) + '-' + ((d.getDate()<10)? '0'+d.getDate() : d.getDate() ) + ' 00:00';
td = d.getFullYear() + '-' + ((d.getMonth()<10)? '0'+(d.getMonth()+1) : d.getMonth()+1 ) + '-' + ((d.getDate()<10)? '0'+d.getDate() : d.getDate() ) + ' 23:59';
}
$('#route-from-date').val(fd).datetimepicker('update', fd);
$('#route-to-date').val(td).datetimepicker('update', td);
$('.datetimepicker').hide();
});
How to add custom button to set the date and close the calender in bootstrap-datepicker?
It is because you are trying to put an object inside something that hasn't created yet.
So I prepared this sample for you, edit according to your needs.
$("#FilterEndDate").on("click",function(){
if($(".datepicker-dropdown").children("button").length == 0)
{
$(".datepicker-dropdown").append("<button>Test</button>");
}
});
Related Topics
Getcomputedstyle Gives "Transparent" Instead of Actual Background Color
Fixed Positioned Element Flicker in Ie Only, How to Solve
Detecting Load of <Link> Resources
Random Fullscreen Background Image on Browser Refresh
Why Are Initial CSS Styles Not Visible on Dom Element.Style Field
CSS Select All Previous Siblings for a Star Rating
Nav-Collapse Not Working [Twitter Bootstrap]
Jquery UI Datepicker: Don't Highlight Today When It Is Also Selected
Random Path Generation Algorithm
Find Unused CSS Rule and Js Script in a Web Project
Find Next Cell Contained in Sibling Row with Queryselector
How to Disable Smooth Scrolling in Ie11
How to Have HTML-Webpack-Plugin Generate <Style> Elements from CSS
Uncaught Domexception: Failed to Read the 'Rules' Property from 'Cssstylesheet'