filmov
tv
How to disable future date in bootstrap datepicker

Показать описание
How to disable future date in bootstrap datepicker
To disable future dates in a Bootstrap datepicker, you can use the endDate option to set the maximum selectable date. This prevents users from choosing dates beyond the specified end date.
Assuming you are using the Bootstrap datepicker plugin, here's an example of how to disable future dates:
html
!DOCTYPE html
html
head
titleDisable Future Dates - Bootstrap Datepicker/title
!-- Include Bootstrap CSS --
!-- Include Bootstrap Datepicker CSS --
/head
body
div class="container mt-5"
h3Select a Date (Future Dates Disabled)/h3
input type="text" class="form-control" id="datepicker"
/div
!-- Include Bootstrap and jQuery --
!-- Include Bootstrap Datepicker JS --
script
$(document).ready(function () {
// Initialize the datepicker with the endDate option set to today's date
$('#datepicker').datepicker({
endDate: new Date() // Disables future dates
});
});
/script
/body
/html
In this example, the datepicker will be initialized with the endDate option set to today's date, which means users won't be able to select any date in the future. Modify the endDate value if you want to set a different maximum selectable date.
Make sure to include the required CSS and JavaScript files for Bootstrap and the Bootstrap datepicker plugin to make this example work correctly.
To disable future dates in a Bootstrap datepicker, you can use the endDate option to set the maximum selectable date. This prevents users from choosing dates beyond the specified end date.
Assuming you are using the Bootstrap datepicker plugin, here's an example of how to disable future dates:
html
!DOCTYPE html
html
head
titleDisable Future Dates - Bootstrap Datepicker/title
!-- Include Bootstrap CSS --
!-- Include Bootstrap Datepicker CSS --
/head
body
div class="container mt-5"
h3Select a Date (Future Dates Disabled)/h3
input type="text" class="form-control" id="datepicker"
/div
!-- Include Bootstrap and jQuery --
!-- Include Bootstrap Datepicker JS --
script
$(document).ready(function () {
// Initialize the datepicker with the endDate option set to today's date
$('#datepicker').datepicker({
endDate: new Date() // Disables future dates
});
});
/script
/body
/html
In this example, the datepicker will be initialized with the endDate option set to today's date, which means users won't be able to select any date in the future. Modify the endDate value if you want to set a different maximum selectable date.
Make sure to include the required CSS and JavaScript files for Bootstrap and the Bootstrap datepicker plugin to make this example work correctly.
Комментарии