javascript - AngularJS 1 form validation in the loop -
i have problem angulare code. have made small form structure ng reapet . when removed 1 of element every element down of them not show "not valid" message . of them work fine down of remove not showing info not given false of data-ng-show="zhf.w{{key}}.$error.pattern" why ng show not taked false.
<form name="zhf" class="form-horizontal"> <div data-ng-repeat="(key, i) in vm.items.info | limitto: (vm.numberofdays)"> <div class="col-sm-3"> <input type="text" class="form-control" id="w{{key}}" name="w{{key}}" ng-model="vm.item[key].w" placeholder="0" ng-pattern="/^[0-9]{1,10}([,.][0-9]{1,2})?$/" required> <p style="color: #a94442" class="text-danger" data-ng-show="zhf.w{{key}}.$error.pattern"> <span>not valid number!</span> </p> </div> <div class="col-sm-2"> <button type="button" class="btn btn-danger btn-sm " ng-click="vm.delete(key)">remove</button> </div> </div> </form> vm.delete = function(index) { vm.items.info.splice(index, 1); vm.item.splice(index, 1); vm.numberofdays -= 1; }
i have updated ng-repeat section validate form , sample here
<form novalidate="novalidate" name="inputvalidate"> <div ng-repeat="field in fields.test"> <div style="width:600px"> <div ng-form name="validme" style="width:58%;float:left"> <input id="input{{$index}}" name="input{{$index}}" type="text" ng-model="field.value" ng-pattern="/^[0-9]{1,10}([,.][0-9]{1,2})?$/" required> <span style="color: #a94442" ng-show="validme['input\{\{$index\}\}'].$error.pattern">not valid number!</span> <span style="color: #a94442" ng-show="validme['input\{\{$index\}\}'].$error.required ">number required!</span> </div> <div style="width:20%;float:left"> <input type="button" value="remove" ng-click="delete($index)"/> </div> </div> </div> </form>
Comments
Post a Comment