1

I've a simple form with a <select> and an <input text>; what I need is to disable the input text if the value of an option is true. This is my code:

<div class="form-group">
    <label for="auth">{{ 'SETTINGS.SYSTEM.NET.WIFI.AUTH.LABEL' | translate }}</label>
    <select name="auth" class="form-control"  ng-model="wifi.securitytype">
        <option value="true">{{ 'SETTINGS.SYSTEM.NET.WIFI.AUTH.NONE' | translate }}</option>
        <option value="false">{{ 'SETTINGS.SYSTEM.NET.WIFI.AUTH.WEP' | translate }}</option>
        <option value="false">{{ 'SETTINGS.SYSTEM.NET.WIFI.AUTH.WPA2' | translate }}</option>
    </select>
</div>


<fieldset ng-disabled="wifi.securitytype">
    <div class="form-group" ng-class="{'has-error':wifiForm.password.$invalid && !wifi.securitytype}">
        <label for="password">{{ 'SETTINGS.SYSTEM.NET.WIFI.PASSWORD' | translate }}</label>
        <input class="form-control" name="password" placeholder="{{ 'SETTINGS.SYSTEM.NET.WIFI.PASSWORD_PLACEHOLDER' | translate }}" ng-model="wifi.wpakey" ng-pattern='/^(?!\s*$).+/' ng-model-options="{ updateOn: 'blur' }">
        <span class="help-block ng-hide" ng-show="wifiForm.password.$invalid && !wifi.securitytype">RICHIESTA PASSWORD DI RETE</span>
    </div>
</fieldset>

The problem is that the <fieldset> is ever disabled. Where is my fault?

georgeawg
  • 48,608
  • 13
  • 72
  • 95
ilGiudice
  • 63
  • 1
  • 9

2 Answers2

2

I think you expect the option values to be of a boolean type. But HTML attributes are always strings, so you should evaluate them in both cases, "true" or "false", as pointed here

Try to replace the ng-disabled condition with

<fieldset ng-disabled="'true' === wifi.securitytype">
Community
  • 1
  • 1
Eirini Graonidou
  • 1,506
  • 16
  • 24
0

wifi.securitytype will return 'true' or 'false' which are non empty strings and truthy according to javascript, so your ng-disabled always evaluates to true. you can do as suggested by @Eirini.

Sajan
  • 1,893
  • 2
  • 19
  • 39