Skip to content
This repository was archived by the owner on Jul 1, 2020. It is now read-only.
This repository was archived by the owner on Jul 1, 2020. It is now read-only.

Validation errors aren't diplayed on form load #35

@igortg

Description

@igortg

I have an application where form submissions aren't done explicit by the user, but done "under the hood" while user switch between forms. In this way, user could leave a view with an invalid form data: the data will not be posted, but it's kept alive on the $rootScope.

The problem is when user go back to the invalid form: validation errors are not displayed unless the field is "touched".

I solve the problem by implementing a directive that watch the form $validationSummary attribute, and call checkFormValidity when $validationSummary is filled. See below

app.directive('validateOnload', ['validationService', function (validationService) {
    return {
        restrict: 'A',
        link: function (scope, element, attrs) {
            var validator = new validationService()

            var deregisterCheckForm = scope.$watch('form.$validationSummary', function () {
                if (scope.form.$validationSummary) {
                    validator.checkFormValidity(scope.form)
                    deregisterCheckForm()
                }
            })
        }
    }
}])

I wonder if this behaviour shouldn't be added to the library as an option. What do you think?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions