角度js日期验证消息

时间:2020-05-25 03:57:11

标签: javascript angularjs

我正在尝试从日期开始到日期验证(日期> fromdate)。

请检查我的html代码

    From Date <input type="text" placeholder="From Date" id="fromDate" min-view="1"
ng-change="getFromMonth(newcashbenifit.toDate, newcashbenifit.fromDate);"
name="cbFromdate" ng-model="newcashbenifit.fromDate" autoclose="true" bs-datepicker />


To Date<input type="text" placeholder="To Date" id="toDate" min-view="1"
 ng-change="getToMonth(newcashbenifit.toDate, newcashbenifit.fromDate);"
 class="form-control" name="cbTodate" autocomplete="off"
ng-model="newcashbenifit.toDate" bs-datepicker />

我正在使用以下功能对此进行验证。请检查以下功能

        $scope.getToMonth = function (selectedToMonth,selectedFromMonth){

            if(selectedFromMonth > selectedToMonth ){
                    $scope.cashBenefitForm.cbTodate.$setValidity("message", false)
            }else{
                $scope.cashBenefitForm.cbTodate.$setValidity("message", true)
            }
         }

         $scope.getFromMonth = function (selectedToMonth,selectedFromMonth){
            if(selectedFromMonth > selectedToMonth ){
                    $scope.cashBenefitForm.cbFromdate.$setValidity("message2", false)
            }else{
                $scope.cashBenefitForm.cbFromdate.$setValidity("message2", true)
            }
          }

验证工作正常。请检查下图。 enter image description here

验证工作正常。现在我将“从日期”更改为“ 04/2020”。在这种情况下,迄今为止仍会出现验证。它应该删除,因为现在todate> fromdate。检查附件图像 enter image description here

我如何正确执行此验证。 ?

0 个答案:

没有答案