通过比较日期angularjs进行表单验证

时间:2016-04-21 06:29:07

标签: angularjs validation

即使datefrom大于dateto,是否有任何简单的方法可以禁用提交按钮?并且必须禁用它,直到表格有效,有效日期,datefrom必须小于dateto

<div class="form-group">
        <div class="col-lg-4 col-md-4 col-sm-5 col-xs-5 col-lg-offset-1 col-md-offset-2 col-sm-offset-1">
            <label class="control-label">Date from:</label>
            <p class="input-group">
             <input type="text" onkeypress='return event.charCode >= 44 && event.charCode <= 57' class="form-control" ng-model="recp.OdK" name="datefrom" id="datefrom" data-date-format="dd.MM.yyyy" bs-datepicker data-autoclose="1" required/>
            <span class="input-group-btn">
                                <button type="button" class="btn btn-default" ng-click="Opened=true;$event.stopPropagation();">
                                    <i class="glyphicon glyphicon-calendar"></i>
                                </button>
                            </span>
                            <p>
        </div>

        <div class="col-lg-4 col-md-4 col-sm-5 col-xs-5">
            <label class="control-label">Date to:</label>
            <p class="input-group"> 
            <input type="text" onkeypress='return event.charCode >= 44 && event.charCode <= 57' class="form-control" ng-model="recp.DoK" name="dateto" id="dateto" data-date-format="dd.MM.yyyy" bs-datepicker data-autoclose="1" required/>
            <span class="input-group-btn">
            <button type="button" class="btn btn-default" ng-click="Opened1=true;$event.stopPropagation();">
                                    <i class="glyphicon glyphicon-calendar"></i>
                                </button>
                              </span>
                            </p>
        </div>
    <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1">
      <button type="submit" ng-disabled="recpForm.$invalid" id="buto" class="btn btn-primary glyphicon glyphicon-ok prikButton" ng-click="precp();precpnp();precprb();recpss();"></button>
    </div>

1 个答案:

答案 0 :(得分:0)

好的,我通过比较ng-disabled中的日期解决了这个问题:

<button type="submit" ng-disabled="recpForm.$invalid || recp.OdK > recp.DoK" id="buto" class="btn btn-primary glyphicon glyphicon-ok prikButton" ng-click="precp();precpnp();precprb();recpss();"></button>