Date Validation
/*
* source :sfdcmonkey.com
* 12/26/2017
*/
({
/*call dateUpdate function on onchange event on date field*/
dateUpdate : function(component, event, helper) {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0!
var yyyy = today.getFullYear();
// if date is less then 10, then append 0 before date
if(dd < 10){
dd = '0' + dd;
}
// if month is less then 10, then append 0 before date
if(mm < 10){
mm = '0' + mm;
}
var todayFormattedDate = yyyy+'-'+mm+'-'+dd;
if(component.get("v.myDate") != '' && component.get("v.myDate") < todayFormattedDate){
component.set("v.dateValidationError" , true);
}else{
component.set("v.dateValidationError" , false);
}
},
submit : function(component,event,helper){
// get the 'dateValidationError' attribute value
var isDateError = component.get("v.dateValidationError");
if(isDateError != true){
alert('date is valid.. write your more logic here...');
}
}
})