Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

ng-model not reflecting invalid state however input is applying class correctly.  #8473

@zackarychapple

Description

@zackarychapple

I have the following input with validation. I cannot get the formError to show up when the input is in an invalid state. The class is being applied to the input however not to the model.

<div class="form-group" ng-class="{'has-error': myObj.ssn.$invalid}">
    <label for="ssn" class="field-label">SSN:</label>
     <div class="field-value">
        <input type="text" name="ssn" id="ssn" class="form-control" ng-model="myObj.ssn" ng-pattern='/^\d{3}-?\d{2}-?\d{4}$/'>
        <div class="formError" ng-show="myObj.ssn.$invalid">Please enter a valid ssn.</div>
    </div>
</div>

HTML after editing the text in the input to be invalid.

<div class="form-group" ng-class="{'has-error': myObj.ssn.$invalid}">
    <label for="ssn" class="field-label">SSN:</label>
    <div class="field-value">
        <input type="text" name="ssn" id="ssn" class="form-control ng-untouched ng-dirty ng-invalid ng-invalid-pattern" ng-model="myObj.ssn" ng-pattern="/^\d{3}-?\d{2}-?\d{4}$/">
        <div class="formError ng-hide" ng-show="myObj.ssn.$invalid">Please enter a valid ssn.</div>
    </div>
</div>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions