Jack Clouseau
Jack Clouseau

Reputation: 81

Max value error message on number type input

I have a number type input box in my form. I have set the min and max value for this. However i want to display a error message to the user when he enters more than the specified max value.

I have written the ng-show, but still the error message won't show up when the user enters more the max value

Below is my code:

<div class="col-sm-8">
<input type="number" class="form-control" name="maxvaluetest" id="maxvaluetest" ng-model="maxvaluetest" min="0" max="100" ng-change="record()" 
ng-required="showError">
<span class="help-block" style="color:red" ng-show="myform.maxvaluetest.$dirty && myform.maxvaluetest.$invalid">
    <span ng-show="myform.maxvaluetest.$error">{{myform.maxvaluetest.$error}}</span>
</span>

Am i missing something here?

Is there any alternative to display the error message? Am using Angularjs

Upvotes: 1

Views: 3399

Answers (1)

Michael Tempest
Michael Tempest

Reputation: 834

You need to use angulars version of min and max. I.E

ng-min="0" ng-max="100"

Also, I think the error that occurs will no longer be required, it will probably be.

myform.maxvaluetest.$error.max

If you put this in your HTML it will print out the version to use for your error message

{{myform.maxvaluetest.$error}}

Upvotes: 1

Related Questions