0

I have a simple Angular form here:

<form class="form-horizontal" role="form" name="alertForm">

    <div class="form-group">
        <label for="cautionMultiplier" class="col-sm-2 control-label">Yellow Multiplier</label>
        <div class="col-sm-5">
            <input type="number" min="1" class="form-control" ng-model="alert.cautionMultiplier" id="cautionMultiplier" name="cautionMultiplier" placeholder="Ex. 2" integer required />
            <span>{{alertForm}}</span>
            <span class="alert alert-danger help-block" ng-show="alertForm.cautionMultiplier.$error.number && alertForm.amount.$dirty">
                                    The value is not a valid integer
                                </span>
            <span class="alert alert-danger help-block" ng-show="alertForm.cautionMultiplier.$error.min ">
                                    The value must be at least 1 and an integer
                                </span>
        </div>
    </div>

    <div class="form-group">
        <div class="col-sm-2">
            <button type="submit" class="btn btn-primary pull-right" ng-click="addAlert(form)" ng-disabled="alertForm.$invalid">
                Save
            </button>
        </div>
    </div>
</form>

When I enter any non integer (ie 'a') into the cautionMultiplier box, the validation message The value is not a valid integer does not trigger.

What am I doing wrong?

2 Answers 2

0

You're displaying this error message only if there is an error for the key "required":

ng-show="alertForm.cautionMultiplier.$error.required && alertForm.amount.$dirty"

Replace required by number.

2
  • I made that change and still nothing... I reflected the change in an edit above.
    – JSK NS
    Commented Jan 2, 2015 at 7:04
  • Ah, my problem was that: alertForm.amount.$dirty should have been alertForm.cautionMultiplier.$dirty
    – JSK NS
    Commented Jan 2, 2015 at 7:08
0

Fixed

My problem was that: alertForm.amount.$dirty should have been alertForm.cautionMultiplier.$dirty

Not the answer you're looking for? Browse other questions tagged or ask your own question.