I know you can set startdate when initialising your datepickers within the config settings. I havn't found a way to add an attribute within the html input to do this.
The way I got around this was like so.
$('.date-picker').each(function () {
if($(this).attr("startdate") !== undefined) {
$(this).datepicker({ format: "dd/mm/yyyy", weekStart: 0, autoclose: true, startDate: $(this).attr("startdate") });
}
else {
$(this).datepicker({ format: "dd/mm/yyyy", weekStart: 0, autoclose: true });
}
});
I write this out in Razor with the following
@Html.TextBoxFor(model => model.SomeDate, new { @class = "date-picker", @data_date = "12-02-2012", @startdate = "12-04-2012" })
Could any one suggest the right way?
This is working for me which is cool for now, it adds a disabled css class on anything before the date 12-04-2012.
You need to use .data() rather than .attr()
<input type="text" class="date_picker" data-start-date="2012-01-01">
and then
$('.date-picker').each(function () {
var config = { format: "dd/mm/yyyy", weekStart: 0, autoclose: true };
if ($(this).data("startDate") != undefined) {
config.startDate = $(this).data("startDate");
}
$(this).datepicker(config);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.