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?

2 Answers 2

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">
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.