Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change CSS when it's ng-disabled?

Tags:

css

angularjs

I have this button:

<input type="submit" value="@Translator.Translate("PAYOUT")"      class="btn-block secondary-button save-changes padding-8"      ng-disabled="PayoutEnabled==false" ng-click="PayOut()" /> 

But even when it's disabled it has the same class as it's enabled, just not clickable. I want to change background when it's disabled so that user can see that button, is disabled. How can I do that? Do I need some ng-disabled CSS class or there is some other way?

like image 608
None Avatar asked Jul 03 '15 11:07

None


People also ask

How do I style a disabled button in CSS?

To make the disabled button, we will use the Pure CSS class “pure-button-disabled” with the class “pure-button”. We can also create a disabled button using disabled attribute. Disabled Button used Class: pure-button-disabled: It is used to disable the Pure CSS button.

How do I give conditions in NG disabled?

The ng-disabled directive sets the disabled attribute of a form field (input, select, or textarea). The form field will be disabled if the expression inside the ng-disabled attribute returns true. The ng-disabled directive is necessary to be able to shift the value between true and false .

How do I select a disabled element in CSS?

The :disabled selector is used to select the disabled element. This property is mostly used on the form elements. Example 1: html.

What is disabled CSS?

The :disabled CSS pseudo-class represents any disabled element. An element is disabled if it can't be activated (selected, clicked on, typed into, etc.) or accept focus. The element also has an enabled state, in which it can be activated or accept focus.


Video Answer


2 Answers

What Toress answered should work fine but you don't need the help of AngularJS here at all (a native implementation & usage is always best).

You can make use of CSS3 since you already have a class on it. Example:

input.save-changes {     /* some style when the element is active */ }  input.save-changes[disabled] {     /* styles when the element is disabled */     background-color: #ddd; } 

Edit: You can immediately test it on this page of StackOverflow. Just inspect the blue button element and put the disabled attribute and see it's CSS.

.save-changes {    background-color: red;    padding: 7px 13px;    color: white;    border: 1px solid red;    font-weight: bold;  }  .save-changes[disabled] {    background-color: #FF85A1  }
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>    <div ng-app ng-init="PayoutEnabled = true">    <a href="#" ng-click="PayoutEnabled = !PayoutEnabled">    {{PayoutEnabled ? 'Disable' : 'Enable'}} the below button</a>    <br>    <br>      <input class="save-changes" type="submit" value="PAYOUT" ng-disabled="PayoutEnabled == false" />  </div>
like image 200
Shashank Agrawal Avatar answered Sep 26 '22 00:09

Shashank Agrawal


use ng-class

<input type="submit" value="@Translator.Translate("PAYOUT")" class="btn-block  secondary-button save-changes padding-8" ng-disabled="PayoutEnabled==false"  ng-click="PayOut()" ng-class="{'diabled-class': !PayoutEnabled}" /> 

this will add css class diabled-class to the input when PayoutEnabled is false (!PayoutEnabled is true).

like image 43
Kalhan.Toress Avatar answered Sep 23 '22 00:09

Kalhan.Toress