Answer the question
In order to leave comments, you need to log in
ng-model list validation?
Tell me how to write a validation.
<form class="ownForm" name="basket" >
<div class="ownForm-row" ng-repeat="(key, value) in form.items">
<div class="ownForm-label">
Продукт - <b> {{ value.name }} </b>
</div>
<div class="ownForm-param">
<input type="text" class="form-control" ng-model="value.quantity" name="quantity[{{key}}]" ng-pattern="/^[1-9]\d*$/" required>
<button class="btn btn-danger" ng-click="deleteItem(key)">Удалить</button>
<div ng-show="basket.$submitted && basket.quantity[key].$invalid" class="ownForm-error">
<span ng-show="basket.quantity[key].$error.required"> Это обязательное поле </span>
<span ng-show="basket.quantity[key].$error.pattern"> Введите положительное число </span>
</div>
</div>
</div>
</form>
Answer the question
In order to leave comments, you need to log in
Solved a problem. The bottom line is that he considered quantity[19] to be a string, not an array. Solved the problem like this:
<input type="text" class="form-control" ng-model="value.quantity" name="quantity-{{key}}" ng-pattern="/^[1-9]\d*$/" required>
<div ng-show="basket.$submitted && basket['quantity-' + key].$invalid" class="ownForm-error">
<span ng-show="basket['quantity-' + key].$error.required"> Это обязательное поле </span>
<span ng-show="basket['quantity-' + key].$error.pattern"> Введите положительное число </span>
</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question