Dosti
Dosti

Reputation: 163

Input validation in AngularJS

I have 2 textbox controls "Low" and "High". High field should not accept a value lesser than Low, I did this validation,

<input id="txtLow" class="txtCell" ng-model='data.low'>
<input id="txtHigh" class="txtCell" ng-model='data.high'>
<button id="btnSave"  ng-click="saveData()">Save</button>
<label ng-show="isInvalid()" class="ErrorMsg">High should be greater than Low</label>

In my controller,

$scope.saveData = function() {
            if (!$scope.isInvalid()) {
                .........
            }
        };
$scope.isInvalid = function () {
            return $scope.data.low > $scope.data.high;
        };

This is working fine. But I need to change the border color of textbox to red instead of showing a label message.

Upvotes: 0

Views: 65

Answers (1)

Abhishek
Abhishek

Reputation: 295

If you don't have css file then add this in html like this

<label ng-show="isInvalid()" class="ErrorMsg" style='class = red;'>High should be greater than Low</label>

Upvotes: 2

Related Questions