JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://code.jquery.com/jquery-1.8.2.js" ></script>
<form ng-app="ai" ng-controller="ConfigCostsPreCalc" name="form">
<h2 class="span6">Required message is not hidden</h2>
Steps to reproduce the problem
<ul>
<li>add a line -> the contained input is empty which makes the form invalid, the required message is shown</li>
<li>remove the line -> the form should be valid now, but the error message is not hidden</li>
</ul>
<h2 class="span1">
<button type="button" ng-click="addYear()" class="btn">+</button>
</h2>
<div class="control-group error regular-line-height">
<span class="help-block" ng-show="showErrorForRepeatedItem(form.$error.required, 'year')">Required message</span>
</div>
<ul class="unstyled numberInput" name="years">
<li ng-repeat="year in years" class="row-fluid">
<span class="span6">
<input type="text" name="year" ng-model="year.year" required class="input-mini"><span> Years</span>
</span>
<span class="span1">
<button type="button" ng-click="removeYears(year)" class="btn">-</button>
</span>
</li>
</ul>
</form>
CSS
input.ng-invalid {
background-color: yellow !important;
}
JavaScript
var appAi = angular.module('ai',[])
appAi.controller('ConfigCostsPreCalc', ["$scope", "$location", "$controller", function ($scope, $location, $controller) {
$scope.years = [{"year":"2"},{"year":"4"},{"year":"5"}];
$scope.addYear = function() {
$scope.years.push({});
}
$scope.removeYears = function(item) {
var index = $.inArray(item, $scope.years)
$scope.years.splice(index, 1); //remove element
}
$scope.showErrorForRepeatedItem = function(violatingInputs, inputExpression){
if(!violatingInputs){
return false
}
var regex = new RegExp(inputExpression);
var hits = $.grep( violatingInputs,
function(el, index){
return regex.test(el.$name);
}).length;
return hits > 0;
}
}]);