【问题标题】:How to check validation on the Div Element using AngularJS?如何使用 AngularJS 检查 Div 元素的验证?
【发布时间】:2015-07-31 20:55:31
【问题描述】:

我正在尝试在下面的字段上添加验证,但我收到错误消息,但它仍然让我保存该字段,我不确定我错在哪里,请帮助..

到目前为止尝试过的代码...

验证.html

<form name="createProcessFormName"
    name="form" role="form" class="form-horizontal"
    kendo-validator="validator" k-validate-on-blur="false"
    k-options="myValidatorOptions" ng-submit="validate($event) && createProcessFormName.$invalid">

    <div class="col-md-7">

        <div multiselect-dropdown-tree ng-model="nonPersistentProcess.geoLocations" ng-class="{'disabled': disableGeoLocations}" disable-children="true" options="treeviewOptions"></div>
            <p class="status" ng-show="geoLocationRequired">*GeoLocation is required field*</p>
        </div>

        <button require-control-point="PROCESS_ADD"
            ng-hide="editMode" class="btn btn-primary pull-right" type="button"
            ng-click="validate($event)">Save</button>

验证.js

$scope.validate = function ($event) {
    if(!$scope.nonPersistentProcess.geoLocations.length || $scope.nonPersistentProcess.epcfKey || $scope.nonPersistentProcess.legalEnty || $scope.nonPersistentProcess.erhKey){
        if($scope.createProcessFormName.$invalid){
            $scope.geoLocationRequired = true;
            $event.preventDefault();
        }
    }

【问题讨论】:

    标签: javascript html angularjs validation


    【解决方案1】:

    尝试将 if 条件更改为:

    if(!$scope.nonPersistentProcess.geoLocations.length || !$scope.nonPersistentProcess.epcfKey || !$scope.nonPersistentProcess.legalEnty || !$scope.nonPersistentProcess.erhKey)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-20
      • 1970-01-01
      • 2021-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多