patm
patm

Reputation: 110

I want to give multiple conditions in ng-disabled

<button type="button" class="btn-submit upload smooth-hover" data-prod-idx="{{index}}" data-prod-id="{{prod.ProductId}}"
ng-click="vm.onUpload($event, index, prod.ProductId)" 
ngf-select="vm.uploadAttachments($event, $files, $invalidFiles)" multiple accept="image/*,.pdf,*.doc,*.docx" ngf-capture="'camera'"
ngf-max-size="5MB" 
ng-disabled="prod.Product_Status === 'Approved||Not Approved'">
Upload Documents</button>
  1. I have different product status condition depending on that I want to disable the button. I am having a problem with or condition in ng-disable. Its not disabling the button if i give to conditions.

2.IF clicked on disabled button it should pop-up the alert message (Not using Jquery) Every condition have different error msg (Conditions in ng-disabled)

Thanks for Help!

Upvotes: 4

Views: 2580

Answers (3)

Carlos Franco
Carlos Franco

Reputation: 210

Your condition code is wrong

ng-disabled="prod.Product_Status === 'Approved'|| prod.Product_Status === 'Not Approved'"

In case 2, you can remove ng-disable and, on click function, you could made with this way:

function onUpload($event, $files, prod.ProductId){
    if(prod.Product_Status === 'Approved'|| prod.Product_Status === 'Not Approved'){
        alert("Message")
        return;
    }
    // your code
}

Upvotes: 3

Pankaj Parkar
Pankaj Parkar

Reputation: 136174

You had wrong expression, it is basically comparing with Approved||Not Approved as string check. Better you could make use indexOf valid statuses array to make your implementation more compact.

ng-disabled="prod.Product_Status === isDisabled(prod.Product_Status)"

Code

//later you can add more status here in this array.
var validStatus = ['Approved', 'Not Approved']; 
$scope.isDisabled = function isDisabled(product_Status){
  return validStatus.indexOf(product_Status) > -1
}

Upvotes: 0

user47589
user47589

Reputation:

It should be:

ng-disabled="prod.Product_Status === 'Approved' || prod.Product_Status === 'Not Approved'"

Putting the || inside the string simply makes it part of the string, not a logical operator.

Upvotes: 1

Related Questions