I have this select :
<select data-bind="options: $root.users(), optionsText: 'name', optionsValue: 'id', value: $root.selectedUser, optionsCaption: 'Select one'"></select>
I only need the default value ('Select one') to be selected if $root.selectedUser = 0 otherwise I don't need the default value.
I tried that:
<select data-bind="options: $root.users(), optionsText: 'name', optionsValue: 'id', value: $root.selectedUser, optionsCaption: $root.selectedUser () === 0 ? 'Select one' : ''"></select>
But it's not working. (if $root.selectedUser = 0 it shows the first value of the list instead of the default value.)
Any idea on how to achieve that?
selectedUsercan't get a0value, when I set it with a0value it getsundefined. WhyselectedUsercan't be0? I added a `console.log() to the fiddle.Selected, to show the actual value selected. Also, I changed the first user to have id = 0. In this link (knockoutjs.com/documentation/options-binding.html) it says thatundefinedvalue shows the default option.valuecan't get a value that is not one of the options of theselect, I managed to solve it, if you want you can write it as an answer and I'll accept it.