1

I'm trying to show one div when a property is true and another if the property is false.

example: http://jsfiddle.net/FgVxY/151/

Using knockout I with the visible binding -> data-bind="visible: testTrue", works fine... But trying -> data-bind="visible: testTrue== false" doesn't...

<div class='eg'>   
<input type='checkbox' data-bind="checked: testTrue" />
<br />
<div data-bind="visible: testTrue">true</div>
<div data-bind="visible: testTrue == false">false</div>    

Does anyone have a sollution for this?

Zaphod
  • 1,412
  • 2
  • 13
  • 27
  • [The "visible" binding](http://knockoutjs.com/documentation/visible-binding.html) in the documentation has an example for this exact thing. See towards the end of the article. – bzlm Oct 06 '14 at 12:49
  • 3
    `showRow` is a function, you need `showRow() == false`: http://jsfiddle.net/FgVxY/149/ In the previous case, knockout just unwraps it for you automatically. – Matt Burland Oct 06 '14 at 12:50
  • @bzlm I know, which is why I didn't understand why my sollution didn't work. – Zaphod Oct 06 '14 at 12:55
  • @MattBurland Thank you!! that seems to work, I'll do some more testing, but I think that cracked it.. – Zaphod Oct 06 '14 at 12:56
  • @Zaphod In the section on "Using functions and expressions to control element visibility" (which you are doing), you can see the need for parentheses to let you use parameters in code. The beginning of the article only uses view model properties as parameters. – bzlm Oct 06 '14 at 13:11
  • @bzlm I've updated the example to more accurately describe my issue, please have a look – Zaphod Oct 06 '14 at 13:16
  • @bzlm: To be fair, I don't think that is really as clear as it could be in the docs. – Matt Burland Oct 06 '14 at 13:16
  • @MattBurland I've updated the example to more accurately describe my issue, please have a look. As you can see my property isn't a function, and I'm not allowed to use the described sollution... – Zaphod Oct 06 '14 at 13:17
  • The question is worded/titled as if it's different, but I still think this is a possible duplicate of [Is it possible to data-bind visible to the negation ("!") of a boolean ViewModel property?](http://stackoverflow.com/questions/10114472/is-it-possible-to-data-bind-visible-to-the-negation-of-a-boolean-viewmodel). – Jeroen Oct 06 '14 at 13:18
  • @Jeroen I've tried the sollution in that post, but it doesn't work as I can't access my property as a function (apparently). Let me know if you see any issues with my code that I'm missing. – Zaphod Oct 06 '14 at 13:21
  • Weird. With [`visible: showRow() == false` it works as expected for me](http://jsfiddle.net/2Lu98zfj/). And [so does the (equivalent) `visible: !showRow()` version](http://jsfiddle.net/2Lu98zfj/1/) mentioned in linked question. Which makes sense, 'cause `showRow` *is* an function in your example (i.e. `ko.observable()` returns a function, this is the way KO works). – Jeroen Oct 06 '14 at 13:27
  • @Jeroen Sorry, try the new jsfiddle link.. It has a better example http://jsfiddle.net/FgVxY/151/ --> I forgot to press the update before posting last link – Zaphod Oct 06 '14 at 13:32

1 Answers1

0

I found the sollution.. I was kind of looking at the worng place, so thanks to those who tried to help, but my question was unpresise.

We use Kendo ui and hence knockout js. I thought the issue was with knockout visible binding, and I still believe there is issues with that, but the sollution was with kendo.

Kendo has an invisible binding, which is the opposite to the visible binding. Using invisible lets you test for 'false' rather than 'true'.

Zaphod
  • 1,412
  • 2
  • 13
  • 27