In my MVC application, I can assign the datepicker class to all of the input boxes requiring date fields. Previously I could then set up my datepicker with the following properties (which worked);
$(".datePicker").datepicker({
showOn: 'both',
dateFormat: 'dd MM yy',
changeMonth: true,
changeYear: true,
yearRange: 'c-1:c+1',
beforeShowDay: noWeekendsOrHolidays });
Now I need to assign a date of birth datepicker that requires a different setup. So for that element I wrap the element as follows;
<span class="allDates"><%: Html.EditorFor(model => model.Employee.Dob)%></span>
So when my View is rendered, the Html from View Source looks like;
<tr>
<td style="text-align: right;">
<label for="Employee_Dob">Date of Birth</label>
</td>
<td colspan="2">
<span class="allDates">
<input class="datePicker" id="Employee_Dob" name="Employee.Dob" type="text" value="" />
</span>
</td>
</tr>
Now my jquery does not work - I imagine this is a simple fix for someone;
$(function () {
$(".datepicker").each(function() {
if ($(this).parent().hasClass("allDates")) {
$(this).datepicker({ showOn: 'both', dateFormat: 'dd MM yy', changeMonth: true, changeYear: true, yearRange: 'c-100:c' });
} else {
$(this).datepicker({ showOn: 'both', dateFormat: 'dd MM yy', changeMonth: true, changeYear: true, yearRange: 'c-1:c+1', beforeShowDay: noWeekendsOrHolidays });
}
});
});