user2433194
user2433194

Reputation: 86

Setting visibility of the Text Box based on the dropdown value selected in Knockout.JS

I have the following dropdown

<select class="sf-dropdown" data-bind="options: Statuses, optionsText: 'Description', value: SelectedStatus, valueAllowUnset: false"></select>

And if the dropdown value selected is 'Not Completed' (which has status value of 0), I want the textbox to appear.

I have my textbox as

<input type="text" id="txtTaskReason" style="width: 40%" data-bind="with: SelectedStatus, visible: SelectedStatus()==='Not Completed', value: Reason" />

However it doesn't seem to work. Any ideas on what I am doing wrong? Thanks

Upvotes: 1

Views: 151

Answers (1)

lagerone
lagerone

Reputation: 1767

It looks like the SelectedStatus value is an object so if you change to

visible: SelectedStatus() && SelectedStatus().Description ==='Not Completed'

it might work.

Upvotes: 1

Related Questions