Skip to content
This repository was archived by the owner on Jan 5, 2022. It is now read-only.
This repository was archived by the owner on Jan 5, 2022. It is now read-only.

Cannot read property 'controls' of undefined #7

@ONbik-srebollo

Description

@ONbik-srebollo

Hi.

Another issue, this is easy to fix.

I have a form without fom controls defined, I submit manually. When I manage changed by click or change events, all works fine. But if I press enter key on an input, it throws an error because there is no controls.

ERROR TypeError: Cannot read property 'controls' of undefined
at FormValidationDirective.webpackJsonp.../../../../ng-bootstrap-form-validation/ng-bootstrap-form-validation/ng-bootstrap-form-validation.es5.js.FormValidationDirective.markAsTouchedAndDirty (ng-bootstrap-form-validation.es5.js:23)

On the code, it assumes that there are controls on the form (2nd line of the function):

    /**
     * @param {?} formGroup
     * @return {?}
     */
    FormValidationDirective.prototype.markAsTouchedAndDirty = function (formGroup) {
        var _this = this;
        Object.keys(formGroup.controls).forEach(function (key) {
            if (formGroup.controls[key] instanceof FormGroup) {
                _this.markAsTouchedAndDirty(/** @type {?} */ (formGroup.controls[key]));
            }
            else {
                formGroup.controls[key].markAsDirty();
                formGroup.controls[key].markAsTouched();
                formGroup.controls[key].updateValueAndValidity();
            }
        });
    };

This error can be prevented if input variable is checked of undefined, and in this case, do nothing.

I'll try to fix it and make a pull-request.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions