2017-01-23 1 views
0

AngularJs에 ng-repeat 섹션을 추가했습니다. 필자는 필수 필드 유효성 검사기를 추가했습니다. 그러나 스팬 태그 데이터가 나타나므로 모든 필드가 비워지면 페이지 높이가 증가합니다. 오류를 설명하는 ng-repeat 섹션 다음에 하나의 오류 메시지 만 표시 할 수 있습니까? 현재의 UI 코드는 다음과 같습니다 :ng-repeat 섹션 다음에 오류 메시지가 표시됩니다.

<div class="row" ng-if="selectedSeasonType"> 
        <div class="form-group "> 
         <label class="form-group col-md-3">Language</label> 
         <label class="form-group col-md-4">Title</label> 
         <label class="form-group col-md-5">Description</label> 
        </div> 
       </div> 
       <br /> 



      <div class="row" ng-repeat="Descriptions in seasonsWithDescription" ng-if="selectedSeasonType"> 
        <div class="form-group col-md-2 top-Margin-language"> 
         <label ng-model="Descriptions.Language">{{Descriptions.Language}}</label> 
        </div> 
        <div class="form-group col-md-4 top-Margin-Title"> 
         <input type="text" maxlength="150" class="form-control input-md" required="" name="titleValidate_{{$index}}" ng-model="Descriptions.Title" /> 
         <span style="color:red" ng-show="submitted == true && mainForm.titleValidate_{{$index}}.$error.required">Title is required</span> 
        </div> 
        <div class="form-group col-md-5"> 
         <textarea maxlength="500" class="form-control input-md noresize" required="" name="descriptionValidate_{{$index}}" noresize="" ng-model="Descriptions.Description"></textarea> 
         <span style="color:red" ng-show="submitted == true && mainForm.descriptionValidate_{{$index}}.$error.required">Description is required</span> 
        </div> 
        <div class="form-group col-md-1"> 
         <a style="cursor:pointer"> 
          <img ng-src="{{DeleteIcon_url}}" alt="delete image" ng-click="($index == !selectedDeleteIcon) || seasonsWithDescription.splice($index,1)" ng-class="{'disabled': $first}" /> 
         </a> 
        </div> 
       </div> 

어떻게 AngularJS와에 필요한 데이터를 설명하는 NG-구간 반복 후 하나의 오류 메시지를 추가? 감사합니다.

+0

ng-repeat 섹션 다음에 나만의 맞춤 오류 메시지를 추가 할 수 있습니까? – sisyphus

+0

안녕하세요, 적어도 10 행이 있습니다. 여기에는 제목 텍스트 상자와 설명 텍스트 영역이 있습니다. 나는 확실하지 않다, 오류 메시지를 표시하는 방법. "제목"이 비어 있거나 "설명"이 비어 있거나 둘 다 비어있을 수 있습니다. – venkat14

+0

그게 보입니다. 당신은 당신의 질문에 더 구체적이어야합니다. 지금 당장 "제목"이 있다고 해두겠습니다. 비어있는 각 제목에 대해 오류 메시지를 표시 하시겠습니까? 또는 제목 중 하나가 누락 된 경우 하단에 오류 메시지 하나를 표시 하시겠습니까? 전자의 경우, 당신은 당신이하고있는 것을 계속해야 할 것입니다. 후자의 경우, ng-show/hide 메커니즘을 사용하는 사용자 정의 오류 메시지가 필요합니다. 한 가지 방법은 모든 비어 있지 않은 제목에 대한 카운터를 갖는 것입니다. 카운트가 반복 크기보다 작 으면 오류를 표시하십시오. – sisyphus

답변

0

의견을 바탕으로 귀하의 필요에 맞게 plnkr입니다.

$scope.isTitleMissing = false; 

$scope.cars = [{id: 1, 'brand': 'Chevy', 'model': 'Camarro'}, 
{id: 1, 'brand': 'Ford', 'model': 'Mustang'}, 
{id: 1, 'brand': 'Hyundai', 'model': 'Santa Fe'}, 
{id: 1, 'brand': 'Honda', 'model': 'CRV'}, 
{id: 1, 'brand': 'BMW', 'model': '350'}] 


$scope.submitForm = function(){ 

var ctr = $scope.cars.length; 
var titleCtr = 0; 
for(var i = 0 ; i < ctr ; i++){ 
    if($scope.cars[i].title != null){ 
    titleCtr++; 
    } 
} 
// 

if(titleCtr < ctr){ 
    $scope.isTitleMissing = true; 
}else{ 
    //continue with submit 
    $scope.isTitleMissing = false; 
    // alert('Total cars - ' + ctr + ' and total Title '+ titleCtr); 
} 

총 레코드 수와 총 타일 수의 합계입니다. 후자가 전체 레코드보다 작 으면 오류 메시지가 표시되고 다른 메시지는 계속 제출됩니다.

희망이 도움이됩니다.

관련 문제