SteveSanderson/knockout — Issue #344: Bug in select box binding "value"
Author: NoiZy
Created: 2012-02-24 10:35:36+00:00
State: open

Hi,

I already postet this to the Google Group, but I think here is a better place for it.

Here my text:
> I found a nesty bug in Knockout with selectboxes.
> I have one defined like that:
> bind="options: Title, optionsText: 'Text', optionsValue: 'Value',
> value: SelectedTitle">
>
Mr

>
Mrs

>
> And I have an Subscription to SelectedTitle like this:
> myViewModel.SelectedTitle.subscribe(function(newValue) {
> alert(newValue);
> alert($("#Title").val());
> $("#Title").multiselect("refresh");
> });
> And the bug is, that "newValue" is ever correct but $("#Title").val()
> is not, it is everytime the value from before, means if I change the
> select from Mr to Mrs $("#Title").val() is "Mr" and if I change it
> back to Mr its "Mrs".
> Means that my Multiselect Refresh doesent work correct.
> I expect that the subsription runs AFTER the underling DOM element is
> updated?!

And the answer to that was:
"Wrap your call to `multiselect("refresh")` in a setTimeout call as the DOM has not been updated yet. I've run into this myself a few times.
The subscriptions are synchronous and the DOM update hasn't happened yet. Just curious, what's the call to multiselect for?"

But I'm not happy with answer, the fact that he is run a few times into it, says to me that Knockout is not working like expected, right?!
So, my wish would be, that Knockout proof internaly, maybe with an infinite while loop which proof if $("#Var").val() == newValue, which means the DOM is updatet and only then execute the subscription.

Is this a dream that can came true?

Best regards