I have table
with ng-repeat
for table rows. I want to make inline editing and validation of data from single row, but it is impossible to use form
or ng-form
inside table.
For inline editing I use inputs with ng-show
inside td
.
So, I have two questions:
Is it correct approach for inline editing? (using hidden inputs inside td).
How can I validate data from row?
Update: I want for table row something like "form submitting" and add error class for table cells with wrong data.
I'm new to angular.
A validator in Angular is a function which returns null if a control is valid or an error object if it's invalid. For model-driven forms we create custom validation functions and pass them into the FormControl constructor.
Form Validation AngularJS also holds information about whether they have been touched, or modified, or not. You can use standard HTML5 attributes to validate input, or you can make your own validation functions. Client-side validation cannot alone secure user input. Server side validation is also necessary.
NG-Form works on elements that are not a HTML form. So, you should be able to use the built ng-form validations inside a table. It seems to track the forms properly per row for me.
https://docs.angularjs.org/api/ng/directive/form
<tr ng-repeat="market in markets | orderBy:'name'" ng-form name="myForm">
<td>{{market.id}}</td>
<td ng-class="{'has-error': !myForm.minimum.$valid}">
<input type="number" name="minimum" min="0" max="10000" ng-model="market.minimum" />
</td>
<td ng-class="{'has-error': !myForm.cash.$valid}">
<input type="number" ng-model="market.cash" min="0" name="cash" />
</td>
<td>
<input type="submit" ng-disabled="!myForm.$valid" ng-click="save(market)"/>
</td>
</tr>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With