David Tunnell
David Tunnell

Reputation: 7532

Disable input field for certain situations

I have an input with angular directives.

<input type="text" class="form-control dropdown-toggle" data-toggle="dropdown" data-ng-disabled="formReadOnly" data-ng-model="item[item.fields[0].name]" data-ng-keyup="comboBoxNDCOptions(2, 69, item[item.fields[0].name], 'searchNdc')" />

I want to add logic so that if a certain situation occurs the input field will be disabled. (un-editable)

So inside the input I'm trying to add the following:

{{true ?  'ng-disabled="true"' : ''}}

it should always evaluate to true in this case and thus add ng-disabled="true".

However its not functioning as expected:

<input {{true ? 'ng-disabled="true"' : ''}} type="text" class="form-control dropdown-toggle" data-toggle="dropdown" data-ng-disabled="formReadOnly" data-ng-model="item[item.fields[0].name]" data-ng-keyup="comboBoxNDCOptions(2, 69, item[item.fields[0].name], 'searchNdc')" />

What am I doing wrong and how do I fix it?

Upvotes: 1

Views: 47

Answers (1)

Vivz
Vivz

Reputation: 6620

Your syntax is wrong. You can check some condition on ng-disabled. You can replace x==y with your logic that will evaluate to either true or false.

<input ng-disabled="x==y?true:false" type="text" class="form-control dropdown-toggle" data-toggle="dropdown" data-ng-disabled="formReadOnly" data-ng-model="item[item.fields[0].name]" data-ng-keyup="comboBoxNDCOptions(2, 69, item[item.fields[0].name], 'searchNdc')" />

Upvotes: 1

Related Questions