Hello,
I've just started using KO and I've encountered two issues:
1) I have an observable in my view model called selectedOrg, which initially contains null, but if the user selects something from a list, it becomes non-null. I'm using it like this:
<input data-bind="value: selectedOrg().name">
Unfortunately, this generates an exception when the page is first started "Unable to parse bindings, value: selectedOrg().name, Cannot read property "name" of null", but it works after that - if a user selects an item, the value is changed as expected. I understand why this is happening (selectedOrg() really is null at first), but how to tell KO that this is ok and the binding should be "skipped" in this case? This INPUT element is in a DIV which has a "visible: selectedOrg() != null" binding, so it will not be shown to users.
2) I actually have two DIVs, one which is supposed to be shown when the user has editing rights on the selected item, containing a HTML form and other stuff, and one which is shown when the user does not have sufficient rights, only showing certain elements. I've decided on doing it like this because the data shown and the use cases are very different in those cases. This is my current test code:
<div id="orgedit" data-bind="visible: selectedOrg() != null && selectedOrg().level >= 90">
<input data-bind="value: selectedOrg().name">
</div>
<div id="orgdisplay" data-bind="visible: selectedOrg() != null && selectedOrg().level < 90">
<span data-bind="text: selectedOrg().name"></span>
</div>
Unfortunately, this fails in a bizarre way: only the first DIV works, whichever of the two I have first in my code. For the second, neither the visible nor the text/value binding works. The only way I can explain this is if the exception in binding selectedOrg().name stops KO from processing other binding, in which case it reduces to my first problem. Am I right?