Perform logic on change of DateTime field
Writing business logic on change of DateTime field in CRM portal using jQuery is different than normal on change function.
eg. If we want to check whether entered date is in past or not then we will use following syntax :
In our case Start Date is the field where we are adding validation. Schema name for start date is new_startdate
var dpcontrol = $("#new_startdate_datepicker_description").closest("div.control");
$(dpcontrol).on("dp.change", function (e)
{
var dateVal = $("#new_startdate").val();
if (dateVal != null) {
var newDate = new Date(dateVal), now = new Date();
newDate.setHours(0,0,0,0); now.setHours(0,0,0,0);
if (newDate < now) {
alert("Date is in past. Please select valid date.");
$("#new_startdate_datepicker_description").val('');
}
}
});
Comments
Post a Comment