Reputation: 5802
Im using DatePicker plugin for a project. But I want to Disable dates older than today .(User couldnt select the old dates) My js is:
datePickerController.createDatePicker({
formElements:{"inp1":"d-ds-m-ds-Y"} });
In manual :Both methods accept an Object that represents the dates or date ranges to disable.
I couldnt disable the old days yet with many trial and error. Can you please show me any way to do this?
Thanks in advance
Edit:
datePickerController.setRangeLow("myElementID",$today);
datePickerController.setRangeHigh("myElementID",$old_dayes);
I want to set dynamic date in ("myElementID","20081201")
.
Date ranges : $today
and $old_days = 'dates older than $today'
Upvotes: 3
Views: 11295
Reputation: 1658
If you are wondering to disable old dates then try this.
$(function() {
var date = new Date();
var currentMonth = date.getMonth();
var currentDate = date.getDate();
var currentYear = date.getFullYear();
$('#validity_picker').datetimepicker({
format: 'YYYY-MM-DD',
minDate: new Date(currentYear, currentMonth, currentDate)
});
});
Upvotes: 0
Reputation: 176
For a more simpler method than upiic's:
function () {
$('#DatePickerControlName').datepicker({maxDate: 0});
});
NB. The 0 means zero days from now.
Upvotes: 2
Reputation: 682
For simple solution see: this site. Fast & easy :)
$(function () {
var date = new Date();
var currentMonth = date.getMonth();
var currentDate = date.getDate();
var currentYear = date.getFullYear();
$('#YourDatepicker').datepicker({
maxDate: new Date(currentYear, currentMonth, currentDate)
});
});
Upvotes: 5
Reputation:
from the docu (note: this is exactly the link you've posted!)
Limiting date selection i.e. setting date ranges
The datePicker enables you to define both a lower and upper limit for date selection.
To add a lower or upper limit, just add the parameters “rangeHigh” and/or “rangeLow” to the initialisation object and set their values to be a YYYYMMDD date format String; for example, the following code will limit date selection outside of the range 13/03/1970 to 20/12/1999:
var opts = {
formElements:{"inp1":"d-sl-m-sl-Y"},
// Set a range low of 13/03/1970
rangeLow:"19700313",
// Set a range high of 20/12/2009
rangeHigh:"20091220"
};
datePickerController.createDatePicker(opts);
for those, who are not willing to scroll (just one line down in the docu)...
Setting the date range dynamically
The upper and lower date ranges can also be set programmatically by calling the following two methods:
// Set the lower limit to be 01/12/2008
datePickerController.setRangeLow("myElementID","20081201");
// Set the upper limit to be 01/12/2009
datePickerController.setRangeHigh("myElementID","20091201");
edit:
html:
<input type="text" id="datepicker"/>
javascript:
var today = new Date();
var options = {
formElements: {
"datepicker": "d-sl-m-sl-Y"
},
rangeLow: today.getFullYear() + today.getMonth() + today.getDay(),
};
datePickerController.createDatePicker(options);
Upvotes: 3