Corner form validation using JSON Schema dynamically

I need to dynamically check json in AngularJS. I ran into a problem loading fields from a schema to a page. I am new to AngularJS, so I don't have that knowledge. I created a form, but I can’t check it dynamically.

    myApp.controller('appController', ['$scope','$http', function($scope, $http) {
        var NUMBER_REGEXP = /^[0-9]+$/;

        $http({ method: 'GET', url: 'JsonSchema.json' })
            .then(function successCallback(response) {
                $scope.data = angular.fromJson(response);
                $scope.data = $scope.data.data;
                console.log($scope.data);
            });

        $scope.greeting = 'success!';

        $scope.handleErrors = function (data) {
            if(data !== undefined && data !== null) {
                angular.forEach(data, function(value, key) {
                    var form = value.form.field;
                    var fields = value.fields.field;
                    var error = form.errors;

                    if(form.compulsory) {
                        $scope.pageError = form.errors.compulsory;
                    }
                    else if(!(NUMBER_REGEXP.test(filds.field))) {
                        $scope.pageError = error.regex;
                    }
                    else {
                        $scope.pageError = "An unexpected error has occurred, please try again later!";
                    }
                });
            }
        }
    }]);
+4
source share
1 answer

The plunker usually helps with this type of problem, but ultimately it depends on which library you use to work with JSON Schema for verification?

AngularJS, JSON Schema , , . .

, , ajv djv .

0

Source: https://habr.com/ru/post/1663235/


All Articles