Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selectmenu selection does not change observable value #41

Closed
bernesto opened this issue Aug 26, 2014 · 6 comments
Closed

Selectmenu selection does not change observable value #41

bernesto opened this issue Aug 26, 2014 · 6 comments

Comments

@bernesto
Copy link

When changing the value of a selectmenu, the underlying observable does not change. If listening to the the "change" event on the selectmenu, and triggering a "change" event on the underlying select element, it does then work.

@gvas
Copy link
Owner

gvas commented Aug 31, 2014

@bernesto: the underlying observable you mentioned is an observable bound to knockout's value binding, isn't it?

<select data-bind="selectmenu: {}, value: valueObservable">...</select>

@bernesto
Copy link
Author

bernesto commented Sep 2, 2014

Yes. Something similar to this:

<select data-bind="selectmenu: myOptions, value:  myValue">...</select>

<script>
var myModel = {
    myOptions : ko.observableArray(['Opt 1', 'Opt 2']),
    myValue : ko.observable('')
}
ko.applyBindings(myModel);
</script>

Also, I couldn't get it working with an array of objects bound to the label either.

It renders fine, it just will not perform two-way binding in either case for the myValue property. I can put together a more detailed example if needed.

@gvas
Copy link
Owner

gvas commented Sep 2, 2014

No need for a more detailed example, thanks.
The jQuery UI selectmenu widget uses a custom event (selectmenuchange) to indicate that the select's value changed. Knockout's value binding listens to the standard change event, so it can't update the bound observable.
The solution will be to modify my selectmenu binding to trigger change in the selectmenuchange's handler, basically it should act as a bridge between the two events. Actually I have already implemented this in the developer branch, I am going to merge it into master and make a new release.

@gvas gvas closed this as completed Sep 2, 2014
@bernesto
Copy link
Author

bernesto commented Sep 2, 2014

Awesome. That is what I was thinking too. Glad to see you are on top of it.

Seems like this might be the case in some of the other jQuery UI controls that have non-standard events plus properties that could be bound to observables. (e.g. spinner, tabs, menu, accordion) I have not used them yet in this project, but they have similar usage scenarios. What do you think?

@gvas
Copy link
Owner

gvas commented Sep 2, 2014

Oops, it was closed accidentally.

@gvas gvas reopened this Sep 2, 2014
@gvas
Copy link
Owner

gvas commented Dec 24, 2014

Fixed in v2.2.0.

@gvas gvas closed this as completed Dec 24, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants