My requirement is, I have two calendar datepicker controls. FromDate
and ToDate
. What I want is, Whenever a User add a date in FromDate
and then he adds the date in ToDate
. The ToDate should not be less than the FromDate
. Also here one more thing is. After one rows, my calendar controls are dynamically generated on add class
click. See my below html
<tr id="vendorlisttr1">
<td>
<div class="row noPadding vendorForm">
<div class="vendorDaterow">
<div class="vendorName" id="dvVendorNameData1">
<label>SP Vender Name</label><span><input type="text" value="" name="nmVendorData" id="txtVendorName1" /></span>
</div>
<div class="vendorFromDate">
<label>From Date</label><span class="datepicker"><input type="text" value="" name="spFromDate" id="spFromDate1" /><i class="fa fa-calendar" aria-hidden="true"></i></span>
</div>
<div class="vendorToDate">
<label>To Date</label><span class="datepicker"><input type="text" value="" name="spToDate" id="spToDate1" /><i class="fa fa-calendar" aria-hidden="true"></i></span>
</div>
</div>
<div class="add">
<i class="fa fa-plus" aria-hidden="true"></i>
</div>
</div>
</td>
</tr>
And below is the datepicker code which I tried for validaton but it's not working.
function addVendorRow() {
var numItems = $('.vendorName').length;
if (numItems != 6) {
var tr2 = $("#vendorlisttr" + (numItems - 1) + "");
var tr = "<tr id='vendorlisttr" + numItems + "'><td><div class='row noPadding vendorForm'><div class='vendorDaterow'><div class='vendorName' id='dvVendorNameData" + numItems + "'><label>SP Vender Name</label><span><input type='text' value='' name='nmVendorData" + "' id='txtVendorName" + numItems + "'/></span></div><div class='vendorFromDate'><label>From Date</label><span class='datepicker'><input type='text' value='' name='spFromDate" + "' id='spFromDate" + numItems + "' /><i class='fa fa-calendar' aria-hidden='true'></i></span></div><div class='vendorToDate'><label>To Date</label><span class='datepicker'><input type='text' value='' name='spToDate" + "' id='spToDate" + numItems + "' /><i class='fa fa-calendar' aria-hidden='true'></i></span></div><div class='minus'><i class='fa fa-minus' aria-hidden='true'></i></div></div></td></tr>"
$(tr).insertAfter(tr2);
$('#txtVendorName' + numItems).focus().autocomplete(autocompleteOptions);
$('#spFromDate' + numItems).datepicker({
dateFormat: 'dd/mm/yy',
numberOfMonths: 2,
onSelect: function (selected) {
var dt = new Date(selected);
dt.setDate(dt.getDate() + 1);
$('#spToDate' + numItems).datepicker("option", "minDate", dt);
}
});
$('#spToDate' + numItems).datepicker({
dateFormat: 'dd/mm/yy',
numberOfMonths: 2,
onSelect: function (selected) {
var dt = new Date(selected);
dt.setDate(dt.getDate() - 1);
$("#txtFrom").datepicker("option", "maxDate", dt);
}
});
} else {
jAlert(ValidationMessageConfig.MaxVendor, ValidationMessageConfig.Title);
}
}
Please help me in validating.
update
Took reference from HERE