2014-06-17 7 views
0

입력 한 금액이 설정된 양보다 많은지 확인하는 사용자 지정 양식 유효성 검사 지시문을 작성했습니다. 그럴 경우 사용자에게 경고하고, 그렇지 않으면 양식을 평소와 같이 제출합니다.사용자 지정 양식 유효성 검사 지시문이 입력 데이터를 전달하지 않음

제가하는 데 문제는 I 입력에 입력 I 양이 양식을 제출하면 스토리지에 데이터를 푸시 제어부에 의해 픽업되지 않는다는 것이다.

나는 대신이

{ "date": "2014-06-17T09:14:51.340Z", "status": false } 

를 얻을이

{ "amount": 1222, "date": "2014-06-17T09:14:51.340Z", "status": false } 

// 형태

<form name="removeMoney" ng-submit="removeEntry()" novalidate> 

       <label class="error"> 
       <input 
        type="number" 
        name="subAmount" 
        placeholder="Remove money from wallet" 
        ng-model="subtractAmount" 
        ng-pattern="/^\d{0,9}(\.\d{1,2})?$/" 
        custom-validation /> 
       </label> 

       <small class="error" ng-show="removeMoney.subAmount.$error.customValidation"> 
       You can't remove more than {{ total | currency:'£' }} 
       </small> 

       <small class="error" ng-show="removeMoney.subAmount.$error.pattern"> 
       Please enter values with no/two decimal points only -- 0.00 
       </small> 

       <button type="submit" ng-disabled="removeMoney.$invalid" class="button postfix alert">Remove</button> 

     </form> 

// 컨트롤러

$scope.removeEntry = function() { 
    var date = new Date(); 

    $scope.walletItems.push({amount:$scope.subtractAmount, date:date, status:false}); 
    $scope.subtractAmount = ""; 
    $scope.removeMoney.$setPristine(); 
} 

// 지침

app.directive('customValidation', function() { 
return { 
    restrict: 'A', 
    require:'ngModel', 
    link: function(scope, elem, attrs, ctrl) { 
     ctrl.$parsers.unshift(function(value) { 
      var minimum = ctrl.$viewValue; 
      if (minimum > scope.total) { 
       ctrl.$setValidity('customValidation', false); 
      } else { 
       ctrl.$setValidity('customValidation', true); 
      } 
     }); 
    } 
} 
}); 
+0

어떤 콘솔 오류는 무엇입니까? 그렇지 않으면 문제에 대한 피 들러를 설정할 수 있습니까? – V31

+0

콘솔 오류가 없습니다. 바이올린을 설정하려고합니다. 가능한 빨리 게시 할 것입니다 –

+0

지시문을 사용하지 않고 양식을 제출할 때 모든 데이터가 전달되고 양식이 올바르게 작동해야 문제가 지시문이나 방식대로 명확히 나타납니다. 그걸 써. –

답변

0

값을 반환하지 않았습니다. 그래서 양식을 제출할 때 아무 일도 일어나지 않습니다.

app.directive('customValidation', function() { 
return { 
    restrict: 'A', 
    require:'ngModel', 
    link: function(scope, elem, attrs, ctrl) { 
     ctrl.$parsers.unshift(function(value) { 
      var minimum = ctrl.$viewValue; 
      if (minimum > scope.total) { 
       ctrl.$setValidity('customValidation', false); 
      } else { 
       ctrl.$setValidity('customValidation', true); 
      } 
      return value; 
     }); 
    } 
} 
}); 
관련 문제