0

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.

4
  • 1
    Create class with needed styling and use ng-class="{'your-class' : isInvalid()}" Commented Dec 5, 2014 at 11:14
  • Actually the answer provided by @Kutyel is better ;) Commented Dec 5, 2014 at 12:17
  • Because ng-class is more for custom things, when validations comes from the "box" in angular. Commented Dec 5, 2014 at 12:22
  • Can we show a balloon message at right corner of textbox instead label? Commented Dec 8, 2014 at 5:50

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.