Reputation: 986
I know its too silly to ask this,But am confused y is this not working.Even though every values looks fine in debug mode.
Actually what I want to achieve is to display error if productionStartFrom
is less than current date.
Controller
scope.currentDate={};
scope.checkDate=function(productionStartFrom){
currentDate = $filter('date')(new Date(), "dd/MM/yyyy", "UTC");
console.log(currentDate); //28/04/2017
console.log(productionStartFrom); //05/04/2017
if(currentDate > productionStartFrom){
scope.dateErrMsg="Date cant be less than today";
alert("Invalid Date");
scope.myForm.$invalid="true";
}
else if(currentDate < productionStartFrom){
scope.dateErrMsg="";
}
}
html page
<datepicker date-format="dd/MM/yyyy" selector="form-control">
<input name="productionStartFrom" type="text" ng-model="produce.productionStartFrom" pattern="(0[1-9]|1[0-9]|2[0-9]|3[01])/(0[1-9]|1[012])/[0-9]{4}"
ng-minlength="10" maxlength="10" x-ng-change="checkDate(produce.productionStartFrom)" /> </datepicker>
Upvotes: 0
Views: 47
Reputation: 21
scope.currentDate={};
scope.checkDate=function(productionStartFrom){
currentDate = $filter('date')(new Date(), "dd/MM/yyyy", "UTC");
console.log(currentDate);
if(currentDate >= productionStartFrom){
scope.dateErrMsg="Date cant be less than today";
alert("Invalid Date");
scope.myForm.$invalid="true";
}
else if(currentDate <= productionStartFrom){
scope.dateErrMsg="";
}
}
Upvotes: 1
Reputation: 1104
you can try like the below code,
$scope.checkDate=function(productionStartFrom){
currentDate = $filter('date')(new Date(), "dd/MM/yyyy", "UTC");
productionStartFrom = $filter('date')(new Date(productionStartFrom), "dd/MM/yyyy", "UTC");
if(currentDate > productionStartFrom){
$scope.dateErrMsg="Date cant be less than today";
console.log("Invalid Date");
}
else if(currentDate < productionStartFrom){
$scope.dateErrMsg="Valid Date";
}
}
Upvotes: 0