0
<td>
  <div>
    <ng-form name="mrpForm">
        <input type="number" min="1" name="mrp" step="any" ng-model="sku.mrp" style="width:80px;" / required>
        <span style="color:red;" ng-if="(mrpForm.mrp.$error.min)">Must be greater than zero</span>
    </ng-form>
  </div>
</td>
<td>
  <ng-form name="packQtyform">
    <input type="number" name="skupackQty" min="2" max="100" ng-model="sku.packQty" style="width:100px;" />
    <span style="color:red;" ng-if="(packQtyform.skupackQty.$error.min)">Must be greater than 1</span>
    <span style="color:red;" ng-if="(packQtyform.skupackQty.$error.max)">Maximum 100</span>
  </ng-form>
</td>
<td>
  <button class="col-md-12 col-sm-12 col-xs-12 btn btn-sm blue" ng-disable="!sku.mrp"
ng-click="addsku(sku);>Save</button>
</td>

In the above code, I want to make save button disable only if a sku.packQty value is an error and if sku.mrp empty,sku.packQty can be empty but it should not be an error If error message save button must be disabled.

Sam
  • 1,115
  • 1
  • 8
  • 23
Ambika KU
  • 91
  • 6
  • In `button` you have an `ng-click` that you don't close the quotes on. – Sam Dec 16 '15 at 11:22
  • Possible duplicate of [angular validation - prevent button ng-click() when form is invalid](http://stackoverflow.com/questions/33695738/angular-validation-prevent-button-ng-click-when-form-is-invalid) – Paulo Scardine Dec 16 '15 at 11:38

2 Answers2

0

I would create a function like:

$scope.valid_form() {
  //here are all the terms, return false if something is wrong
  return true;
}

And then, in my html button I will simply say:

ng-disabled="!valid_form()"
Amit
  • 5,924
  • 7
  • 46
  • 94
0

You can use form-name.$invalid for this.

<button class="col-md-12 col-sm-12 col-xs-12 btn btn-sm blue" ng-disable="!sku.mrp || mrpForm.$invalid || packQtyform.$invalid"
ng-click="addsku(sku);>Save</button>

I couldn't understand the validation conditions but $invalid would do.

Jithin
  • 2,594
  • 1
  • 22
  • 42