user1789573
user1789573

Reputation: 535

AngularJS select drop-down not RED per required

I have a required field that works great. I have it with the tag "required" such that every time the screen initializes then that field will have a red outline around the box. It's a select with (s) and the red outline works during initialization. However, once i discard some changes and make the field null or empty string (i.e. field = "") the red outline disappears. Why is that?

Here is some HTML:

Status: <select ng-model="customerStatus" data-z-required required>
                            <option></option>
                            <option value="A">Active</option>
                            <option value="L">Lapsed</option>
                            <option value="P">Pending</option>
                            <option value="I">Inactive</option>
                        </select>

In my controller i simply set customerStatus = null or customerStatus = "" and neither gives me a red border. In fact, it's actually the CAUSE for the red border to disappear. How can i get that red box back and clear out any values in the field?

Upvotes: 0

Views: 567

Answers (1)

Adobe Flex Coder 0622
Adobe Flex Coder 0622

Reputation: 135

After you have cleared the values in the form you can call $setPristine(). This will set the value of the form back $pristine. The total call will look like $scope.nameoftheform.$setPristine()

Upvotes: 1

Related Questions