Reputation: 803
I am able to populate a multi-select list using the "options" binding in Knockout in the code below. Now I need to enable a button on the screen only when an option is selected. The problem is that I cannot figure out how to observe whether an option is selected or not. Anyone have an idea?
<select size="8" multiple data-bind="options: viewsForClient, optionsValue: 'Value', optionsText: 'Text'"
Upvotes: 2
Views: 89
Reputation: 8206
you need to use selectedOptions
(read the knockout documentation: http://knockoutjs.com/documentation/selectedOptions-binding.html)
then on the button, you can data-bind something like enable: selectedOptionVariable.length > 0
to enable the button if the selectedOptionsVariable array has a value in it.
Upvotes: 2