Closed dspangen closed 11 years ago
Can you be more specific? This sounds correct: the optionsDefault
value is designed to be a permanently-available first option within the list that the user may always select, regardless of other list contents. By contrast, the optionsEmpty
value is designed to provide a placeholder that fills in the list while no options (or default value) is available.
So, I don't fully follow the nature of your issue as described. Could you please expand your report to include a full description of your scenario, the behavior you expect, and how that differs from the behavior you're experiencing? Thanks.
The problem with optionsDefault is that it adds a value to the list--if you are populating a list from a collection, and want to only offer options from that collection (while selecting a default), you can't do it--the default is added to the list (and will add a duplicate value).
If you want to populate a collection of options without the default, then simply exclude optionsDefault
from the binding. Using just options
will populate the contents of an array or collection; adding optionsDefault
will add a permanent default that exists outside of the collection.
I am facing the same issue, I think what @dspangen means is that, let's say I have the following list:
<select>
<option value="foo">foo</option>
<option value="bar">bar</option>
<option value="baz">baz</option>
</select>
and I want bar
to be selected by default on page load, i.e.:
<select>
<option value="foo">foo</option>
<option value="bar" selected>bar</option>
<option value="baz">baz</option>
</select>
I can't do
<% this.myOptions = [{value: 'foo', label: 'foo'}, {value: 'bar', label: 'bar'}, {value: 'baz', label: 'baz'}] %>
<% this.myDefault = {value: 'bar', label: 'bar'} %>
<select data-bind="value:test,options:myOptions,optionsDefault:myDefault">
because that will generate:
<select>
<option value="bar">bar/option>
<option value="foo">foo</option>
<option value="bar">bar/option>
<option value="baz">baz</option>
</select>
Can we reopen this issue @gmac ?
If you use optionsDefault with options in a binding, the optionsDefault will always prepend the default to the list, instead of, say, using an existing value in the list.