Vikash Vikash - 1 year ago 81
Javascript Question

KnockoutJS data-bind="Visible :" with two conditions is not working

A simple thing I am trying to workout with KnockoutJS.

I have two

and a

What I need

If both the dropdowns are selected, then only I should get the checkbox displayed. Otherwise, the text input should not visible.

What I tried:

Here is my fiddle:

I used something like this:

data-bind="visible: selectedValue && selectedControl"

From the above, the conditions are verified as below:

IF selectedValue IS TRUE AND selectedControl IS NOT UNDEFINED

Kindly provide me a solution and also where I went wrong with it. I am a beginner of

Answer Source

When you use multiple conditions in a binding, you need to unwrap the observables so the entire expression can be evaluated.

To do this, just add brackets after the observable:

<input type="text" class="form-control" data-bind="visible: selectedValue() && selectedControl()" />


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download