Name Last Update
src Loading commit data...
tests Loading commit data...
.gitignore Loading commit data...
.gitlab-ci.yml Loading commit data...
.npmignore Loading commit data...
README.md Loading commit data...
gulpfile.js Loading commit data...
karma.conf.js Loading commit data...
package.json Loading commit data...

Angular Matrix Validation

build status

This module provide an addon directive for form to validate matrix form.

Example

<body ng-app="test" ng-controller="ctrlTest">
    <ng-form name="mForm" matrix-validator data-all="validator">
        <table>
            <tr ng-repeat="row in matrix" ng-init="rowId = $index">
                <td ng-repeat="item in row track by $index">
                    <input ng-model="row[$index]" type="number"
                           data-row="rowId" data-col="$index"
                           name="item{{rowId}}_{{$index}}"
                           ng-class="{error: mForm['item'+rowId+'_'+$index].$invalid}"
                    >
                </td>
            </tr>
        </table>
    </ng-form>
</body>
angular.module('test', ['matrixValidation']).controller('ctrlTest', [
        '$scope',
        ($scope) => {
            $scope.matrix = [
                [0,0,0],
                [0,0,0],
                [0,0,0]
            ];

            $scope.test=2;

            /**
             * @param {mixed[][]} matrix The matrix with the value of form fields
             * @param {null[][]} validationMatrix The validation matrix template.
             * @returns {boolean[][]}
             */
            $scope.validator = (matrix, validationMatrix) => {
                // Do something to fill validationMatrix with true/false
                // to validate matrix.

                // validationMatrix is give to help you to construct it.
                // It have the same dimension than matrix.
                // But you to return it.
                return validationMatrix;
            };
        }
    ]);